Copied to clipboard

Flag this post as spam?

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


  • Mike Driscoll 10 posts 81 karma points
    Apr 27, 2021 @ 15:43
    Mike Driscoll
    0

    Searching the UmbracoFormsRecordIndex

    I'm trying to search the examine index that was included with Umbraco Forms. I can see that the index is healthy and working when I try it from the backend, but it will not return results from my custom search result page on the front end.

    This works for returning external pages:

            if (!String.IsNullOrEmpty(searchTerm) && ExamineManager.Instance.TryGetIndex("ExternalIndex", out IIndex index))
        {
            var searcher = index.GetSearcher();
    
            var criteria = searcher.CreateQuery("content", BooleanOperation.And)
            .GroupedOr(new List<string> { "combinedField" }, searchTerm);
    
            var searchList = criteria.Execute();
            var result = searchList.ToPublishedSearchResults(UmbracoContext.PublishedSnapshot.Content);
    

    But if I simply replace the IndexName, IndexType and Field with the Umbraco Form Index values, nothing will return:

    if (!String.IsNullOrEmpty(searchTerm) && ExamineManager.Instance.TryGetIndex("UmbracoFormsRecordsIndex", out IIndex index))
        {
            var searcher = index.GetSearcher();
    
            var criteria = searcher.CreateQuery("UmbracoForms", BooleanOperation.And)
            .GroupedOr(new List<string> { "RecordFields" }, searchTerm);
    
            var searchList = criteria.Execute();
            var result = searchList.ToPublishedSearchResults(UmbracoContext.PublishedSnapshot.Content);
    

    Am I missing something obvious?

    Thanks! md

  • AddWeb Solution Pvt. Ltd 109 posts 360 karma points
    Apr 29, 2021 @ 04:36
    AddWeb Solution Pvt. Ltd
    0

    Try like this

    if (!String.IsNullOrEmpty(searchTerm) && ExamineManager.Instance.TryGetIndex("ExternalIndex", out var index))
    {
    var searcher = index.GetSearcher();
    
    var criteria = searcher.CreateQuery("content", BooleanOperation.And)
    .GroupedOr(new List<string> { "combinedField" }, searchTerm.ToLower().MultipleCharacterWildcard())
    .And()
    .Field("searchablePath", Model.HomeNode.Id.ToString())
    .Not()
    .Field("umbracoNaviHide", "1");
    
    
    var searchList = criteria.Execute();
    var result = searchList.ToPublishedSearchResults(UmbracoContext.PublishedSnapshot.Content);
    }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies