Equality search returning more results than contains search on same field
I've got a peculiar situation. I am querying a given field through either a form submission or a deeplink. To account for vagueness in the submission, I am allowing for a partial match, i.e. "neuro" would return items for both "neurology" and "neurosurgery," whereas deeplinking in would imply an exact match, i.e. "neurosurgery" would only match against "neurosurgery".
I'm seeing some rather inexplicable weirdness though - if I submit the form with "Internal Medicine" as my query, I'll do my CONTAINS search and return ~200 results (expected). If I do it as an EXACT match on the same field, I return upwards of 1400, the vast majority of which have nothing even remotely matching in that field. I inspected coveo console just to make sure the traffic mirrored what I was seeing and received the following:
Query (@fspecialtygroups5872=="Internal Medicine") performed by coveo\admin [Sitecore Security Provider for mysite]. 1401 results in 0.453 seconds. Query (@fspecialtygroups5872*="*Internal Medicine*") performed by coveo\admin [Sitecore Security Provider for mysite]. 217 results in 0.141 seconds.
I'm hitting the same server and the same index and got the same results when querying through the CES Admin tool as well.
Does anyone have any idea what I'm missing here?
Looking at the field hashing, I believe this is a Coveo for Sitecore solution. This mean that we should be able to grasp the entire query from the browser dev tools. Start by accessing them (f12) and navigating to the network tab. Then try both query again. This should send a POST request. In the header of that request, under the Form Data section, you should see the payload separated in different sections (q, aq, cq, etc…).
"q" is the basic query, so in your case, it should be (@fspecialtygroups5872=="Internal Medicine") for example. this is captured by the CES console. "aq" is the advanced query and is hidden from the console, that might be where you will find the answer to the disparity in results. "cq" is a constant expression. Usually in Coveo for Sitecore, it will contain the source filtering for the website database.
Tell us if you find anything strange by comparing both.