Examine search query using both Boost and Fuzzy search

From Examine there are string extensions for both Fuzzy and Boost.
Both of these act on strings but return IExamineValue’s:

#region Assembly Examine.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=null
// Examine.Core.dll
#endregion

using Examine.Search;

namespace Examine
{
  public static class SearchExtensions
  {
    public static IExamineValue Boost(this string s, float boost);
    public static IExamineValue Escape(this string s);
    public static IExamineValue Fuzzy(this string s);
    public static IExamineValue Fuzzy(this string s, float fuzzieness);
    public static IExamineValue MultipleCharacterWildcard(this string s);
    public static IExamineValue Proximity(this string s, int proximity);
    public static IExamineValue SingleCharacterWildcard(this string s);
  }
}

How would one go about setting up a search against an index where the critera is both Boost-ing and Fuzzy-ing the search term?

Hey Karl

One of the ways to go about this is to create an Extension method for both (Fuzzy and Boost) returning IExamineValue[]?.

In your calling code after you have run CreateQuery (Quick-start | Umbraco CMS) you can use GroupOr to pass in the query you built with something like

query.And().Group(x=> x.GroupedOr("FieldName", searchTerm.Boost) .Or().GroupedOr("FieldName" ,SearchTerm.Fuzzy)

or something similar to that depending on the version of Examine you use as i think there could be slight variations.

Some references can be found here Searching | Examine

I don’t understand all Examine/Lucene nuances, but wouldn’t this just result in:

  • Look for exact match, and if matched, give a score Boost
    OR
  • Look for fuzzy match, and if matched, do NOT give a score Boost
    ?

Instead of being able to do a fuzzy match, and for such a match boost the score.

You can only call Fuzzy on a string, and you can only call Boost on a string. These are methods from Examine itself, so even if I write another string extension method I cannot change the core of Examine to be able to call Boost or Fuzzy on an IExamineValue.

Maybe I misunderstand the approach you suggest, not sure :slight_smile:

Could you add a native lucene expression..

var query = searcher.CreateQuery().NativeQuery("title:query~0.8 ^10");

if that is even correct from a native point of view?

1 Like