Search code examples
azure-cognitive-search

Is there support for Phrase Search with wildcards?


I realize this may be a bit of an edge case. I can search an Azure Search index for a phrase like this: "noel magique".

If I try to search "noe* magi*", it returns nothing. It seems that the wildcard is not taken into account in phrase search. Is that correct?

If not, any ideas on how I might be able to accomplish this? Our solution has an intelligent user search syntax parser, which could take that user input and generate azure search syntax such as the following: keywordSloganLangSearch:(noe*) AND keywordSloganLangSearch:(magi*)

But it isn't exactly the same results, because it will return things I want "Noël magique" but also things I do not want "magie de Noël".

Any ideas?


Solution

  • This is not supported. Phrase queries match only on complete terms.

    To enable this behavior you could set a custom indexing analyzer on the keywordSloganLangSearch field that uses the EdgeNGram token filter. For every token its prefixes of given length will be indexed on the same position (you can control the length with the minGram and maxGram options). Since you have prefixes in the index, you can drop the suffix operator from you queries and search for: keywordSloganLangSearch:"noe magi"

    Note, the index size for that field will increase as you now index multiple terms for every token. Non phrase prefix queries against that field will likely return many unintuitive results, that's why you might want to have a dedicated field just to support those phrase prefix queries.