Copied to clipboard

Flag this post as spam?

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


  • Jesse Andrews 191 posts 716 karma points c-trib
    Sep 21, 2021 @ 23:19
    Jesse Andrews
    0

    Is there a way to include a wildcard in an Examine NativeQuery call?

    I've noticed that Examine strips out the wildcard indicator when using the NativeQuery method. For example, if I pass "someProperty:test*^5" to it, it gets converted to "someProperty:test^5." While adding the wildcard via the Examine MultipleCharacterWildcard string extension does work, I'm not aware of any way of combining that with boosting.

    Is there a setting I'm missing, or is this a limitation of Examine?

  • Mats Stam 66 posts 236 karma points
    Sep 22, 2021 @ 09:26
    Mats Stam
    1

    I honestly can't tell you if there is a way to use it in the NativeQuery, but if you have another way to do the query you want I would go with that and do the boosting when creating the index.

    Like this:

    public class CustomizeIndexComposer : ComponentComposer<CustomizeIndexComponent>
    {
    }
    
    public class CustomizeIndexComponent : IComponent
    {
        private readonly IExamineManager _examineManager;
    
        public CustomizeIndexComponent(IExamineManager examineManager)
        {
            _examineManager = examineManager;
        }
    
        public void Initialize()
        {
            // get the external index
            if (!_examineManager.TryGetIndex(Constants.UmbracoIndexes.ExternalIndexName, out IIndex index))
                return;
            if (!(index is LuceneIndex luceneIndex))
            {
                throw new InvalidOperationException("Could not cast");
            }
            luceneIndex.DocumentWriting += LuceneIndex_DocumentWriting;
    
    
        }
    
        private void LuceneIndex_DocumentWriting(object sender, DocumentWritingEventArgs e)
        {
            if (e.ValueSet.Category == "content")
            {
                var field = e.Document.GetField("heroHeader");
                if(field != null)
                    field.Boost = 29f;
    
                var field2 = e.Document.GetField("nodeName");
                if(field != null)
                    field2.Boost = 30f;
            }
        }
    
        public void Terminate()
        {
        }
    }
    
  • Jesse Andrews 191 posts 716 karma points c-trib
    Sep 22, 2021 @ 16:28
    Jesse Andrews
    0

    I wasn't aware that we could do that. Good to know. While that does work around the issue, it's not quite what I'm looking for, as my search setup allows the boost to be changed from query to query, whereas this approach sets a fixed boost for each field.

  • Sven 34 posts 138 karma points
    Nov 23, 2022 @ 11:56
    Sven
    0

    Hello Jesse, Did you find any solution to this problem? Thanks!

  • Jesse Andrews 191 posts 716 karma points c-trib
    Nov 23, 2022 @ 17:00
    Jesse Andrews
    0

    I wasn't able to make wildcard search work in a native query, so I had to use the examine api to make queries when I needed to support wildcards using the MultipleCharacterWildcard extension. See this thread for a simple example of that. Lost some of the flexibility I had when using native queries, but it's a non issue most of the time.

Please Sign in or register to post replies

Write your reply to:

Draft