A query built using the Sitecore Azure Content Search Provider doesn't produce the query that I was expecting. The result is that far too many results are returned. The purpose of the code is to find specific items in the index, not to search for matches based on a search term.
The code was initially built for Solr, and I'm sure it worked back then.
I think the issue is that Sitecore is using the search option rather than $filter.
The code I've used to create the predicate is as follows:
var predicate = PredicateBuilder.False<RelatedQualificationSearchResultItem>();
foreach (var codeParentPos in codeParentPosPairs)
{
var innerPredicate = PredicateBuilder.True<RelatedQualificationSearchResultItem>();
innerPredicate = innerPredicate.And(i => i.ParentPos == codeParentPos.ParentPos);
if (!string.IsNullOrEmpty(codeParentPos.Code))
{
innerPredicate = innerPredicate.And(i => i.QmdCode == codeParentPos.Code);
}
predicate = predicate.Or(innerPredicate);
}
return predicate;
This is an example generated query (reduced to two inner predicates):
&search=(ParentPos:(1234\-56) AND QmdCode:(111/2222/3)) OR (ParentPos:(4321\-56) AND QmdCode:(333/2222/1))&queryType=full&$count=true
This returns over 250 results from the index.
Instead I want it to use a query like this:
&$filter=(ParentPos eq '1234-56' and QmdCode eq '111/2222/3') or (ParentPos eq '4321-56' and QmdCode eq '333/2222/1')&queryType=full&$count=true
This returns 2 results which in my opinion is what would be expected from the code written.
Is there anything I can do to make this behave as I'd expect? I don't want to have to resort to ditching the Sitecore provider again.