What does WithAndAsDefaultOperator() do?

Vote:
 

I have used QueryStringQuery.DefaultOperator to change the default operator of the query. My intention is to make the search operator 'AND' instead of 'OR'.

IClient client = SearchClient.Instance;
client.Search<SearchType>().For(Query, q=> {
                    q.DefaultOperator = BooleanOperator.And;
                }).Take(1000).GetResult();

And also I have got to know that the WithAndAsDefaultOperator() does the same thing as above ('AND' search instead of 'OR').

IClient client = SearchClient.Instance;
client.Search<SearchType>().For(Query).WithAndAsDefaultOperator().Take(1000).GetResult();

Are these two search implementations do the same thing without any difference in the resultset?

Note: I did not find the WithAndAsDefaultOperator() in the Episerver Find Documentration. It's better if anyone could share the link of that just to refer.

Thanks.

#216440
Edited, Feb 06, 2020 10:17
Vote:
 

Hi Senura,

That is exactly what it does - It's basically an extension method to change the DefaultOperator field as you have shown in your example.

    /// <summary>
    /// Modifies how a free text query will be parsed to require that each individual word be present
    /// in the matched text.
    /// </summary>
    /// <remarks>
    /// By default a free text query for 'EPiServer Find' will be parsed as 'EPiServer' AND/OR 'Find'.
    /// After invoking this method the free text query will instead be parsed as 'EPiServer' AND 'Find.
    /// </remarks>
    public static IQueriedSearch<TSource, QueryStringQuery> WithAndAsDefaultOperator<TSource>(
      this IQueriedSearch<TSource, QueryStringQuery> search)
    {
      return (IQueriedSearch<TSource, QueryStringQuery>) new Search<TSource, QueryStringQuery>((ISearch) search, (Action<ISearchContext>) (context => ((QueryStringQuery) context.RequestBody.Query).DefaultOperator = new BooleanOperator?(BooleanOperator.And)));
    }

I hope that helps answer your question?

Cheers.

#216572
Feb 10, 2020 10:16
Vote:
 

Thanks. This means they both do exactly the same. Now I could safely replace the 1st implementation (Query.DefaultOperator = BooleanOperator.And) with the (.WithAndAsDefaultOperator()).

#216610
Feb 11, 2020 3:10
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.