Last active
August 29, 2015 14:19
-
-
Save komainu85/775fa757f54ae4f6d2f0 to your computer and use it in GitHub Desktop.
Sitecore ContentSearch Lanaguage Culture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace MikeRobbins.Business | |
{ | |
public class Searcher : ISearcher | |
{ | |
public List<SiteSearchResultItem> GetItemsByBaseTemplate(string indexName, ID baseTemplateId, string[] keywords) | |
{ | |
using (var context = Sitecore.ContentSearch.ContentSearchManager.GetIndex(indexName).CreateSearchContext()) | |
{ | |
var culture = Sitecore.Context.Language.CultureInfo; | |
var queryable = context.GetQueryable<SiteSearchResultItem>(new CultureExecutionContext(culture)); | |
var query = queryable.Where(x => x.BaseTemplates.Contains(baseTemplateId)); | |
var textQuery = BuildTextQuery(keywords); | |
var results = query.Where(textQuery); | |
return results.ToList(); | |
} | |
} | |
public Expression<Func<SiteSearchResultItem, bool>> BuildTextQuery(string[] keywords) | |
{ | |
var predicate = PredicateBuilder.True<SiteSearchResultItem>(); | |
foreach (var keyword in keywords) | |
{ | |
predicate = predicate.Or(i => i.Title.Equals(keyword) || | |
i.Body.Equals(keyword)); | |
} | |
return predicate; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment