November Happy Hour will be moved to Thursday December 5th.

Unified Search - Using AnyWordBeginWith on all fields

Vote:
 

Is it possible to use wildcard or AnyWordBeginWith filter on the UnifiedSearchFor method?

I took a look at the elastic search documentation which says wildcard characters are can be used as * but adding this onto the end of the words I pass to UnifiedSearchFor() does not appear to work.

I can see there are example of performing wildcard and fuzzzy queries by Joel and Henirck but these are performed at a field level, not across all feilds when using UnifiedSearchFor() method.

Is this possible, or should it not be done because of the performance hit.

Thanks,

Adam

#72508
Jun 19, 2013 10:36
Vote:
 

You cannot use wildcards in UnifiedSearchFor directly as it will be interpreted as the char * and not the 'wildcard'. What you can do is create your own For extension that supports this:

public static IQueriedSearch<TSource, QueryStringQuery> WildcardFor<TSource>(
this ITypeSearch<TSource> search, string queryString)
{

return new Search<TSource, QueryStringQuery>(search, context =>
{
var query = new QueryStringQuery(searchQuery);

context.RequestBody.Query = query;

});
}

 

#72518
Jun 19, 2013 12:51
Vote:
 

Thanks Henrick - works great :)

Just one little mistake on the seachQuery variable name, think it should be queryString

        public static IQueriedSearch<TSource, QueryStringQuery> WildcardFor<TSource>(
            this ITypeSearch<TSource> search, string queryString)
        {
            
            return new Search<TSource, QueryStringQuery>(search, context =>
            {
                var query = new QueryStringQuery(queryString); context.RequestBody.Query = query;
            });
        }

    

#72524
Jun 19, 2013 15:15
Vote:
 

Hi

Best bets doesn't seem to work when this extension method is applied, have you noticed this too Adam?

/Fred

#116559
Feb 02, 2015 10:47
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.