Exclude from search not working until manual reindex trigerred

Tomas Trojcak asked on October 18, 2023 15:54

Hi, in Kentico, if I click exclude from search in a page general properties, the page is still visible in smart search results, until I manually triggers the reindex of indexes. The job Optimize local search indexes did run, but does not affect the search results. Also another question: if I unpublish a folder, should all the items in the folder still appear in the smart search result? Because this is, how it behaves now. Im new to Kentico, so might be, I understand something wrong.

Recent Answers


Jono Rickard answered on October 18, 2023 22:03

Heya Tomas,

Yeah any changes to the configuration of a smart search index requires a manual rebuild of the index.

They do this because with large sites, the reindex can take quite a while to rebuild, and you want to be able to control when that happens to not slow the rest of the site.

Usually though index configuration changes only happen during development, and its worth making all your changes at once before running a reindex.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on October 19, 2023 05:56

What version and hotfix are you using? Are there any errors in the event log? If you are excluding the page from search in Pages app, then this should update the index right ahead - by default. Depending on your search tasks processing configuration. Check whether you are using the key for scheduled updates or not. Then check the search tasks queue to make sure no task is blocking the queue and also check Event log for any errors.
Only the unpublished page is not displayed in the results - unless your search is not configured to display also unpublished pages. So, if you want to hide entire section, you need to unpublish all the pages or, adding excluded content to the search might be faster.

0 votesVote for this answer Mark as a Correct answer

Tomas Trojcak answered on October 19, 2023 09:18 (last edited on October 19, 2023 11:02)

Version v13.0.118. From the two answers, the reindex does not runs automatically, but If there is scheduled job, and it runs OK, then the smart search must not include the excluded pages, right? I dont have to rebuild the index manually at all cost.

And the second quiestion: If folder is not published (red circle with white cross), but it contains published items (green checkmark), which have Exclude from search set to false, should the items appear in smart search, or not, because the parent is not published? Or this might be the answer: "Only the unpublished page is not displayed in the results - unless your search is not configured to display also unpublished pages. So, if you want to hide entire section, you need to unpublish all the pages or, adding excluded content to the search might be faster." thanks

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on October 19, 2023 11:33

Rebuilding an index is a complex and resource consuming operation. So, it is done only when you change the index settings or change the structure of the index - e.g. you change page type fields for a page covered by the index.
Modifying content does not require index rebuild. As described in the documentation I linked, by default the content changes are processed almost instantly. Have you checked the search tasks queue? Have you checked the Event log? Are the search results OK in the search preview? Is the issue only on the Live site? What version and hotfix are you using? Please, answer these questions as they are crucial for further troubleshooting.
When you set to true the Exclude from search then the page record is removed from the index entirely. I just tested it and it is happening instantly for me. I am using Kentico 13 with latest hotfix.
Second question - the pages themselves are published = appear in the search results.

0 votesVote for this answer Mark as a Correct answer

Tomas Trojcak answered on October 19, 2023 13:15

The issue was on all environments. The version of Kentico is v13.0.118. The issue first time occurs a month ago. I was able to reproduce it week ago, the same for my colleagues. Now I tried to Exclude from search, and the results were excluded from search immediately, without the need to rebuild the index. So not sure, what happen there, and why it was not working before. Didnt check the logs and other stuff yet, as they are probably not accessible for me (no content is shown, only loading spinner with blank page)

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on October 19, 2023 13:27

So, now the thing is whether the problem was on the live site or in the search preview. The search indexes are syunchronized through web farms. So, if the results were fine in the search preview but not on the live site, most likely there was a web farm sync issue.

0 votesVote for this answer Mark as a Correct answer

Tomas Trojcak answered on October 20, 2023 17:11

I found another problem: If I try to search on live, or any other env any random string, which should return nothing after search eg "safgerge", the SearchHelper.Search() returns always the same set of results. However, the search preview is working fine in this case, and returns nothing. Any tips, what should I look for?

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on October 22, 2023 04:53

I would recommend checking the search controller and what code you are using inthere. I would also use the Luke tool to inspect and compare the contents of the index files in the fornt end app vs. admin app.

0 votesVote for this answer Mark as a Correct answer

Tomas Trojcak answered on October 22, 2023 12:18

The logic in controller is simple, and I didnt found nothing, that should be the problem there:

public SearchResultModel GetSearchResults([FromQuery] string searchTerm, [FromQuery] string path, [FromQuery] int pageNumber = 1, [FromQuery] int pageSize = 5, [FromHeader(Name = LanguageHeader)] string language = "de") { var culture = LanguageHelper.LanguageToCultureMappingWithFallback(language);

var searchPattern = new SearchPattern($"{searchTerm} title:\"{searchTerm}\" isfeatured:(true)^0.05", SearchOptionsEnum.FullSearch);
var searchParameters = SearchParameters.PrepareForPages(searchPattern, new[] {$"Index_{culture}"}, pageNumber, pageSize, MembershipContext.AuthenticatedUser);
searchParameters.Path = path;

var searchResult = SearchHelper.Search(searchParameters);

return _mapper.Map<SearchResultModel>(searchResult);

} text

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on October 22, 2023 13:44

I do not know your search index setup - but isn't it possible that your search pattern matches all the results? The search preview is using setup as you can see in \CMS\CMSModules\SmartSearch\SearchIndex_Search.aspx.cs file. I would start with some simple code, e.g. like in the sample Dancing Goat project or in the documentation and take it from there.

0 votesVote for this answer Mark as a Correct answer

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