Solr Implementaion in Sitecore JSS with Code (Second Blog) Model,Interface and Repo Code
Code for Solr Repo and additional files
Model.cs
using Sitecore.ContentSearch;
namespace Foundation.Solr.Model
{
public class SearchResultsModel
{
[IndexField("title")]
public string Title { get; set; }
[IndexField("heading")]
public string Heading { get; set; }
[IndexField("_template")]
public string Template { get; set; }
[IndexField("_language")]
public string Language { get; set; }
}
Interface.cs
using Foundation.Solr.Model;
using System.Collections.Generic;
namespace Foundation.Solr.Interface
{
public interface ISearchResultService
{
List<SearchResultsModel> GetSearchResultsService(string searchedText);
}
}
Code for Repo (Remember to register dependencies and use classes)
namespace Foundation.Solr.Repositories
{
public class SearchResultRepository : ISearchResultRepository
{
private ISearchResultService _searchResultService;
public SearchResultRepository(ISearchResultService searchResultService)
{
Assert.ArgumentNotNull(searchResultService, nameof(ISearchResultService));
this._searchResultService = searchResultService;
}
public SearchResults GetSearchResults(string searchedText)
{
var searchResult = new SearchResults();
try
{
var result = _searchResultService.GetSearchResultsService(searchedText);
if (result != null && result.Any())
{
searchResult = result.FirstOrDefault();
}
}
catch (Exception ex)
{
Sitecore.Diagnostics.Log.Error("GetSearchResult is causing error", ex.ToString());
}
return searchResult;
}
}
}
Link for First Part : Solr Blog First Part
Link For Third Part : Solr Blog Third Part
What/Where is code for "ISearchResultRepository" ? SearchResultRepository class implements the ISearchResultRepository interface
ReplyDelete