Unexpected changes to search results with optionalWords

I’m experimenting with using optionalWords to change our query terms from AND to OR, and while most of our queries are returning the same or more results, as expected, a few terms are yielding very surprising results.

My best guess so far is that there’s an interaction between optionalWords and searching array fields in records. Here’s an example of what I’m seeing:

Query: index.search("apples for sale", optionalWords: ["apples fruit"])

Field priority: ["store_name", "products", "advertisements"]

Index: [{store_name: "Plants Incorporated", products: ["apples"], advertisements: "Lots of good fruit this week!"}, { store_name: "Universal Produce", products: ["bananas"], advertisements: "All apples are on sale this week."}]

Expected result: [“Fruit Incorporated”, “Universal Produce”]

Actual result: [“Universal Produce” (match on “advertisements”)]

From looking at the ranking info, it looks like there’s simply no match on the products field when optionalWords is enabled. Setting optionalWords to "" makes the problem disappear, demonstrating that it’s not simply the presence/absence of the optionalWords param that’s causing the problem.

Very puzzled by the above. Would love to know if there’s any documented interaction between arrays and optionalWords, or if something deeper is going on here.

Can talk through a more realistic example in greater depth if helpful.

Hi there!

Could you please provide us a codesandbox replicating your issue by forking this one: https://codesandbox.io/s/github/algolia/doc-code-samples/tree/master/InstantSearch.js/getting-started It’ll help us troubleshoot the issue you are having with optionalWords.

Thanks! Looking forward to your reply.