Kentico 13 Smart Search not working with Local Indexes

Akhilesh Sehgal asked on May 23, 2023 12:24

We are implementing Smart Search in Kentico 13. In our initial we had enabled the search feature, followed by adding local indexes (I added a local index with name "DefaultSearchIndex"). For the indexes we have set the path to a page with sub pages so that search results are considered from sub pages. After doing the configuration when I search from the admin panel under Local Indexes>DefaultSearchIndex>Search preview, I get the correct result.

Now, the issue I am facing is that I want to use the same index at controller end to return a custom view. Here I used the code provided in documentation also shown below

 //Prepares variables required to perform the search operation
            IEnumerable<string> searchIndexes = new List<string> { "DefaultSearchIndex" };

            int pageNumber = 1;
            int pageSize = 1000;
            UserInfo searchUser = MembershipContext.AuthenticatedUser;
            string cultureCode = "en-us";
            /* Indicates whether the search service uses site default language version of pages as a replacement
            for pages that are not translated into the language specified by 'cultureCode' */
            bool combineWithDefaultCulture = true;

            // Prepares a 'SearchParameters' object to search through indexes of the 'Pages' type
            SearchParameters searchParameters = SearchParameters.PrepareForPages(searchQuery, searchIndexes, pageNumber, pageSize, searchUser, cultureCode, combineWithDefaultCulture);



            // Searches the specified indexes
            SearchResult searchResult = SearchHelper.Search(searchParameters);

You can see that I have added the index but when I call this API, this is not returning any results using the index name of the local index.

Secondly, when I rename the Local Index to "Search", this returns the results but for all the nodes, that is it is not considering the selected path in the Indexed content.

Recent Answers


Eric Dugre answered on May 25, 2023 21:43

What is the searchPath variable, and why are you calling Replace() on it? This will generate an invalid path, e.g. if the path is "/Articles/2023" your code will change it to "Articles2023/%"

0 votesVote for this answer Mark as a Correct answer

Akhilesh Sehgal answered on May 30, 2023 10:43

I was using that for some other condition which I forgot to remove in above question. Still unable to get the result

0 votesVote for this answer Mark as a Correct answer

Eric Dugre answered on May 31, 2023 20:38

Can you confirm that the local index files are present in the /AppData/CMSModules/SmartSearch folder of the live site application?

If they are not there, please check that your web farms are configured properly and tasks are being processed: https://docs.xperience.io/configuring-xperience/setting-up-web-farms/troubleshooting-web-farms. If everything looks okay, can you please try rebuilding the index in the CMS admin UI? This should generate a web farm task to generate the index files on the live site application as well.

0 votesVote for this answer Mark as a Correct answer

Amal Almulla answered on July 4, 2023 13:24

why are you using "SearchResult searchResult = SearchHelper.Search(searchParameters);:?

0 votesVote for this answer Mark as a Correct answer

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