Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • damion-daly 5 posts 71 karma points
    Jun 26, 2023 @ 15:57
    damion-daly
    0

    Examine search for Umbraco 10

    I'm trying to build a search to return both matching page titles and matching content from within content pages.

    I have included the code from here to index blocklist content as well. I can find matching page titles no problem but no matter what I try I can't get it to find anything within page content.

    Can anyone post a link to an example that works?

    At the moment I'm working with this:

    public IEnumerable<ResultItem?> SearchUmbraco(string searchTerm, int websiteId)
            {
                  var examineSearcher = _examineManager.TryGetIndex("ExternalIndex", out var externalIndex)
                      ? externalIndex.Searcher
                      : null;
    
                  var criteria = examineSearcher?.CreateQuery("content").GroupedOr(new[] { "nodeName", "content" }, searchTerm);
    
                var filter = criteria.Field("nodeName",     
                ISearchResults results = filter.Execute();
    
                // convert the results to a list of ResultItem objects while filtering out irrelevant results from other sites etc
                var content = results.Select(x => ConvertToResult(int.Parse(x.Id), websiteId, x.Score))
                      .Where(x => x != null)
                .ToList();
    
                  return content.OrderByDescending(x => x.score);
            }
    
Please Sign in or register to post replies

Write your reply to:

Draft