Copied to clipboard

Flag this post as spam?

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


  • danbord 2 posts 22 karma points
    Aug 09, 2023 @ 17:51
    danbord
    0

    Searching for content with wildcard with Examine

    I'm with Umbraco 12, I'm trying really hard to search for content with a specific value with wildcard. All the documentation / posts I stumble upon are outdated.

    What I need : Find any "recipe" document that has either nodeName or shortDesc field containing the filter text in parameter.

    Here's my code :

    var results = index.Searcher.CreateQuery("content")
                            .NodeTypeAlias("recipe")
                            .And(q => q.GroupedOr(new[] { "nodeName", "shortDesc" }, filter))
                            .Execute();
    

    that seems to work but only IF the filter value matches exactly the document value.

    I then tried that :

    var results = index.Searcher.CreateQuery("content")
                            .NodeTypeAlias("recipe")
                            .And(q => q.GroupedOr(new[] { "nodeName", "shortDesc" }, filter.MultipleCharacterWildcard()))
                            .Execute();
    

    It works but only as a wildcard at the end ot the beginning (example: for the word "ceiling", searching for "ceil" would find it, searching for "ling" would not)

    Anyone could give me a working example on how to do this? Or point me to the right up to date documentation?

    Thanks

  • Richard Ockerby 39 posts 214 karma points MVP 5x c-trib
    Aug 15, 2023 @ 00:37
    Richard Ockerby
    0

    This looks likely to be the problem of leading wildcards. I’ve not had a chance to test this on 12 but the principle should be the same as what’s been written here: https://our.umbraco.com/forum/umbraco-8/97707-examine-leading-wildcard#comment-309422

  • danbord 2 posts 22 karma points
    Aug 15, 2023 @ 18:29
    danbord
    0

    Hello Richard, thanks for your reply.

    I already stumbled on the link you provided. I'm just wondering how to set the AllowLeadingWildcard flag.

    In the example you provided it is set by setting query.QueryParser.AllowLeadingWildcard = true.

    In v12, the QueryParser property does not seem to exist on the IQuery interface.

    Thanks

  • 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