Custom smart search by culture

Gleb Itenberg asked on September 26, 2018 14:50

I have a custom search index. Now search index is working but when I add a culture condition it returns null. Here is a part of index where I set culture field:

                        var documentParameters = new SearchDocumentParameters
                        {
                            Index = srchInfo,
                            Type = SearchHelper.CUSTOM_SEARCH_INDEX,
                            Id = Guid.NewGuid().ToString(),
                            Created = DateTime.Now,
                            SiteName = currentSiteName,
                            Culture = siteCulture.CultureCode
                        };

And part of combining search query:

        var searchCondition = culture != null
            ? SearchSyntaxHelper.GetFieldCondition("_culture", culture.ToLower(), true)
            : "";

        var condition = new SearchCondition(searchCondition, SearchModeEnum.AnyWord,
            SearchOptionsEnum.FullSearch);

As a result I get a query like: "+_culture:en-gb +_customfield:(term1 OR term2)"

This query will return null, but if I remove +_culture:en-gb then it will return all items(fro all cultures) according to customfield condition. I have to add that search documents have field "_culture" field.

How can I include filter by culture?

Recent Answers


Peter Mogilnitski answered on September 26, 2018 15:08

In terms of lucene syntax query result should be: +(_culture:en-gb AND _customfield:(term1 OR term2)). I guess you need to use SearchSyntaxHelper.AddSearchCondition

0 votesVote for this answer Mark as a Correct answer

Gleb Itenberg answered on September 27, 2018 08:24

No, that doesn't help

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on September 28, 2018 04:34 (last edited on September 28, 2018 04:34)

the syntax should be ok.

  1. Make sure taht culture en-gb is added to the index (go your index cultures tab)
  2. just in case try +documentculture: en-gb
  3. Get Lukeall and check your index. see if something is indexed for culture
0 votesVote for this answer Mark as a Correct answer

Juan Paulo Roque answered on November 19, 2018 19:37

Gleb, I'm getting the same issue as yours, have you find a solution? Lucene toolbox is correctly returning results using +_culture: en-gb but the result from the var searchResult = SearchHelper.Search(parameters); is 0.

0 votesVote for this answer Mark as a Correct answer

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