Using search term for two websites on umbraco.
# help-with-umbraco
b
Hi, I have two websites on umbraco 12. These are two parent items, each having child items. However I found out when implementing the search umbraco examine doesn't have a function that simply filters content for only one website. So I have to use the recursive function for any one of the parent nodes to go through the items to return the ones that contain the search term. The problem I can forsee is the search will take long to return results if the websites become larger with 100s of pages. If anyone knows a more robust solution that would be much appreciated.
j
All indexed nodes has a path which is a list of node ids of ancestors. The common solution for this is to pass along a rootnode id in the search endpoint and then add a search by path on that id to filter to only the current site
Here is an example of that:
Copy code
csharp
if (!_examineManager.TryGetIndex(Umbraco.Cms.Core.Constants.UmbracoIndexes.ExternalIndexName,
        out var index)) return null;

var pages = index.Searcher.CreateQuery("content")
    .ManagedQuery(query, new[] { $"nodeName_{culture.ToLowerInvariant()}" })
    .And()
    .GroupedOr(new[] { "__NodeTypeAlias" }, ArticlePicker.ModelTypeAlias, ContentPage.ModelTypeAlias, LandingPage.ModelTypeAlias)
    .And()
    .Field("SearchablePath", siteId.ToString())
    .Execute(QueryOptions.SkipTake(0, limit));
One thing to bear in mind is that the "SearchablePath" is a custom field that contains the values from the path split by space instead of commas as they are otherwise not searchable
9 Views