Copied to clipboard

Flag this post as spam?

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


  • JA 2 posts 32 karma points
    Oct 10, 2023 @ 16:19
    JA
    0

    Struggling with basic filtering due to Examine/Lucene's inherent searching

    I have a Umbraco site that's functioning as a database of entries, and each entry has a few checkbox lists, so when you create an entry you tick the checkboxes that apply. Pretty standard.

    We're running into difficulties because in one checkbox list there might be options like 'Fine Motor' and 'Gross Motor' where a word ('Motor') is repeated. On the frontend when you tick ONE filter for either of these options, you'll get the articles with 'Fine Motor' AND 'Gross Motor' as it seems the search is splitting each tag string up by spaces (and special characters) rather than searching by the full string.

    It's saying is there an entry with 'Fine' OR 'Motor' in. I've spent hours trying different variations on And, GroupedAnd, Or, GroupedOr etc. but we can't seem to change the inherent search function which wants to split strings up and do an OR search.

    We tried passing in the string with quotation marks around, but no dice. I'm sure someone else must have solved this as it seems a pretty basic requirement for so many sites. Any advice?

        var query = searcher.CreateQuery("content").Field("__NodeTypeAlias", "measureArticle");
    
        if (!string.IsNullOrWhiteSpace(paginationSettings.SearchTerm))
        {
            string phrase = $"'{paginationSettings.SearchTerm}'";
            query = query.And().GroupedOr(searchFields, phrase);
        }
    
        if (paginationSettings.SelectedAssessmentTypesTags != null && paginationSettings.SelectedAssessmentTypesTags.Length > 0)
        {
            query = query.And().GroupedOr(new List<string> { "relatedAssessmentTypes" }, paginationSettings.SelectedAssessmentTypesTags);
        }
    
        if (paginationSettings.SelectedPurposesTags != null && paginationSettings.SelectedPurposesTags.Length > 0)
        {
            query = query.And().GroupedOr(new List<string> { "relatedPurpose" }, paginationSettings.SelectedPurposesTags);
        }
    
        if (paginationSettings.SelectedPatientGroupsTags != null && paginationSettings.SelectedPatientGroupsTags.Length > 0)
        {
            query = query.And().GroupedOr(new List<string> { "relatedPatientGroups" }, paginationSettings.SelectedPatientGroupsTags);
        }
    
        if (paginationSettings.SelectedAgeGroupsTags != null && paginationSettings.SelectedAgeGroupsTags.Length > 0)
        {
            query = query.And().GroupedOr(new List<string> { "relatedAgeGroups" }, paginationSettings.SelectedAgeGroupsTags);
        }
    
        if (paginationSettings.SelectedAreaOfAssessmentsTags != null && paginationSettings.SelectedAreaOfAssessmentsTags.Length > 0)
        {
            query = query.And().GroupedOr(new List<string> { "relatedAreaOfAssessment" }, paginationSettings.SelectedAreaOfAssessmentsTags);
        }
    
        query = query.And().Field("__Published", "y");
    
        results = query.Execute();
    
    }
    

    E.g. relatedAssessmentTypes is the alias for the checkbox list to search through. paginationSettings.SelectedAssessmentTypesTags is a string[] that contains the tags selected on the front-end.

    The only hack we've had success with so far is to make our own strings with underscores in rather than spaces so that the term is not split up at all. But this isn't presentable to the client.

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Oct 11, 2023 @ 08:30
    Huw Reddick
    100

    Hi JA,

    I believe the only way around this is to add a custom field to the filter that replaces spaces with an underscore, you can the do the same to your search term before doing the query, because as you say the query is splitting it into seperate words.

    Unless anyone knows any different that is.

  • JA 2 posts 32 karma points
    Oct 12, 2023 @ 12:10
    JA
    0

    Thanks Huw. I wasn't sure if you meant this exactly but your input definitely helped us reach the conclusion of adding custom fields to the entries in the Examine Index. These are all one string which are easily searchable with a bit of conversion in the C#. I think you probably meant this.

    Yes, it's not the most comprehensive solution but it's probably the best we can manage with Examine for now. It works and the user wouldn't know otherwise.

Please Sign in or register to post replies

Write your reply to:

Draft