Search: Match single word on phrase, but phrase should not match single word

So if someone is searching my app I may have documents like this

[
{
"flavours": ["Cherry", "Chocolate"]
}, {
"flavours": ["Morello Cherry", "Dates"]
}]

Now I want the search for ‘cherry’ to match on both documents. But I want a search for “morello cherry” to ONLY match the second document. I can’t seem to figure this out. Been trying custom analysers etc but not cracking it. My normal search index is just on standard and have looked into keyword and obviously this solves half the problem e.g I can make it only match Morello Cherry on a search for Morello Cherry, but then Cherry only returns “Cherry” and not Morello Cherry

Could dynamically change the search if its a multi word only use keyword index and if single word use standard but then i’m just pushing the goal posts to three word matches e.g morello cherry pie wouldn’t come up on a search of morello cherry

1 Like

Hi @James_Harding2 ,

Can you show your custom analyzer and index ?

Best,
Shreya

1 Like

Give the phrase operator a try. It’ll work on single or multiword queries and will match when all the search terms appear in the same order.