Copied to clipboard

Flag this post as spam?

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


  • Ken Mark 82 posts 94 karma points
    Aug 23, 2021 @ 14:07
    Ken Mark
    0

    Examine wildcard search

    I'm a bit confused about how to get proper wildcard searches working.

    When building my query like below Examine removes the asteriks (*). And if you for example add MultipleCharacterWildcard it always appends it. I want the user to be able to choose what kind of search to do. How can I accomplish that?

    ISearcher searcher = index.GetSearcher();
    IQuery query = searcher.CreateQuery(null);
    query.GroupedOr(fields, searchValue.Split(' '));
    
  • Huw Reddick 1929 posts 6717 karma points MVP 2x c-trib
    Aug 24, 2021 @ 12:37
    Huw Reddick
    0

    you can use value.MultipleCharacterWildcard() extension tol escape the *, however I have never been able to get it to work if * is the first character lucene just complains.

    so "test" will work, but not "test" very frustrating, have tried pretty much everything but it just errors with

    '*' or '?' not allowed as first character in WildcardQuery

  • Ken Mark 82 posts 94 karma points
    Sep 01, 2021 @ 21:54
    Ken Mark
    0

    Thanks for answering. The problem is that MultipleCharacterWildcard always appends the asterisk. What I wanted to accomplish is that if the users search is "test" it should not be a wildcard search, but if they type "test*" or "te*st" it should.

    After digging into this I ended up with a native query instead.

    Here is the code to solve your problem with an asterisk as first letter

    ISearcher searcher = index.GetSearcher();
    var query = (Examine.LuceneEngine.Search.LuceneSearchQueryBase)searcher.CreateQuery(null);
    query.QueryParser.AllowLeadingWildcard = true;
    
  • Gurumurthy 54 posts 127 karma points
    Nov 09, 2021 @ 17:27
    Gurumurthy
    0

    Hi

    Any solution or code snippet to get results with wild card in Umbraco 8 Examine.

    My expectation would be as per below: search keyword =Net*, which should search for Netapp or Network.

    Thanks In advance.

    Gurumurthy J V

Please Sign in or register to post replies

Write your reply to:

Draft