How can I add culture code to LocationIndex and SearchIndexService?

Mr Who asked on August 21, 2020 12:57

Hello,

I've created local index for site, and I want to add a culture code to the class which I pointed out when creating the index (in indexed content) for configure search. How can I do it?

Correct Answer

Dmitry Bastron answered on August 24, 2020 18:28

You can do it something like this:

var condition1 = SearchSyntaxHelper.GetFieldCondition("_site", SiteContext.CurrentSiteName.ToLower());
var condition2 = SearchSyntaxHelper.GetFieldCondition("_culture", cultureCode);

var combined = SearchSyntaxHelper.AddSearchCondition(condition1, condition2);

Bear in mind you may also need to add SearchSyntaxHelper.GetRequiredCondition which adds additional plus symbol (+) into Lucene search request that means it's a required condition:

var condition1 = SearchSyntaxHelper.GetRequiredCondition(SearchSyntaxHelper.GetFieldCondition("_site", SiteContext.CurrentSiteName.ToLower()));
var condition2 = SearchSyntaxHelper.GetRequiredCondition(SearchSyntaxHelper.GetFieldCondition("_culture", cultureCode));

var combined = SearchSyntaxHelper.AddSearchCondition(condition1, condition2);
1 votesVote for this answer Unmark Correct answer

Recent Answers


Dmitry Bastron answered on August 21, 2020 13:19

Hi,

What type have you used for the index? Is it a Page Type or Module Custom Class? Page Types already contain Culture column that will be added to Pages index automatically. If it is a Module Custom Class, you would need to add a custom field referencing CultureInfo into your class and configure this field to be added to your index.

1 votesVote for this answer Mark as a Correct answer

Mr Who answered on August 24, 2020 14:02

Thank you, but I've a one more question about it. If I want to add a one more condition to exist condition how can I do it? For example, I've already the condition =>

var condition = SearchSyntaxHelper.GetFieldCondition("_site", SiteContext.CurrentSiteName.ToLower(), true);

and I need to add the follow condition =>

SearchSyntaxHelper.GetFieldCondition("_culture", cultureCode, true);

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.