Copied to clipboard

Flag this post as spam?

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


  • Vaggelis Kasapis 3 posts 73 karma points
    Jun 12, 2019 @ 13:48
    Vaggelis Kasapis
    0

    Examine Leading Wildcard

    Hello everyone, Is there any way to enable leading wildcards in examine in umbraco 8?

  • Anton Oosthuizen 206 posts 486 karma points
    Jun 26, 2019 @ 12:48
    Anton Oosthuizen
    0

    Hey did you manage to find a solution?

  • Vaggelis Kasapis 3 posts 73 karma points
    Jun 26, 2019 @ 16:31
    Vaggelis Kasapis
    0

    No man. I didn't please let me know if you find one.

  • Anton Oosthuizen 206 posts 486 karma points
    Jun 27, 2019 @ 06:14
    Anton Oosthuizen
    0

    No documentation on this but the work around was putting the wildcards in the search term *searchterm*

  • Markus Johansson 1936 posts 5864 karma points MVP 2x c-trib
    Jul 11, 2019 @ 15:49
    Markus Johansson
    9

    Hi Guys!

    Just figured I'll share the solution that I came up with. As far as I understand the the abstractions used in Examine don't exponse the configuration in a obvious way (probably for some good reason), so we need to do some casting before we can set the AllowLeadingWildcard-setting.

    We can do this in two ways,

    Either by casting the ISearcher from the .GetSearcher()-method to BaseLuceneSearcher which exposes a .CreateQuery()-method that takes the LuceneSearchOptions():

    var index = ExamineManager.Instance.Indexes.Where(f => f.Name == "ExternalIndex").FirstOrDefault();
    var searcher = (BaseLuceneSearcher)index.GetSearcher();
    var query = searcher.CreateQuery("content", BooleanOperation.And, searcher.LuceneAnalyzer, new LuceneSearchOptions() { AllowLeadingWildcard = true });
    

    Or by casting the query:

    var index = ExamineManager.Instance.Indexes.Where(f => f.Name == "ExternalIndex").FirstOrDefault();
    var searcher = index.GetSearcher();
    
    var query = (LuceneSearchQueryBase)searcher.CreateQuery("content");
    query.QueryParser.AllowLeadingWildcard = true;
    

    This will allow the leading wild card in the terms which is the first thing we need to do.

    Next we can create a IExamineValue that contains the leading wildcard, one might think something like this would work:

    query.And().Field("nodeName", "*term*");
    

    But in the processing of the string the *-s will be stripped out in the generated lucene-query so we have two options here as well:

    Use the .MultipleCharacterWildcard() string extension and making sure that the string we pass contains the leading *

    var value = "*" + "term"; // leading wildcard and term
    query.And().Field("nodeName", value.MultipleCharacterWildcard());
    

    Or pass a IExamineValue for the fieldValue to create "your own" IExamineValue:

    query.And().Field("nodeName", new ExamineValue(Examineness.ComplexWildcard, "*term*"));
    

    Hope my little research on the topics helps to clearify =D

  • Vaggelis Kasapis 3 posts 73 karma points
    Jul 11, 2019 @ 16:41
    Vaggelis Kasapis
    0

    Thanks for the detailed response Markus i will try it and i ll let you know for the results.

Please Sign in or register to post replies

Write your reply to:

Draft