0
votes

I have following records in my Azure Search Index

{ 
    "customerId": "8feda7ca-c9f0-40d9-86d8-434b0bbe94c2", 
    "registeredName": "TeamPeacock", 
    "tradingName": "TeamPeacock", 
}, 
{ 
    "customerId": "b445eb04-8d07-4708-a197-770cda3a459e", 
    "registeredName": "TeamPeacock1", 
    "tradingName": "TeamPeacock 1", 
}

I am using Full Search with wildcard/fuzzy search to fetch records.

Below search queries fail to fetch the above records:

Failed Query 1:

{ 
    "search": "(peacock*) OR (peacock*~) OR (peacock~)", 
    "queryType": "full", 
    "searchMode": "all" 
}

Failed Query 2:

{ 
    "search": "(peacock*) OR (peacock*~) OR (peacock~)", 
    "queryType": "full", 
    "searchMode": "any" 
}

Failed Query 3:

{ 
    "search": "(peacock*)", 
    "queryType": "full", 
    "searchMode": "any" 
}

Failed Query 4:

{ 
    "search": "(peacock*~) OR (peacock~)", 
    "queryType": "full", 
    "searchMode": "any" 
}

But if I include term "teampeacock", search query returns result.

Passed Query:

{ 
    "search": "(teampeacock*) OR (peacock*~) OR (peacock~)", 
    "queryType": "full", 
    "searchMode": "all" 
}

Passed Query:

{ 
    "search": "(teampeacock*~) OR (peacock~)", 
    "queryType": "full", 
    "searchMode": "any" 
}

Why searching with term "peacock" is not returning the data?

1

1 Answers

4
votes

You can use the analyze API to understand how Azure Search create tokens out of your text: https://docs.microsoft.com/en-us/rest/api/searchservice/test-analyzer

In your case, it is expected that search for "peacock*" wouldn't match a document that only contains the term "teampeacock" as there's no delimiters between the term "team" and "peacock". This means that only 1 token ("teampeacock") will be created in your index. Since you used a wild card at the end of "peacock" in your search query ("peacock*"), then tokens that start with "peacock" will be matched, but tokens that start with "teampeacock" won't.

If you want to match anything that contains "peacock", you can use it as an "infix" rather than a "prefix" with the following query:

{ 
    "search": "/.*peacock.*/", 
    "queryType": "full",
    "searchMode":"all"
}

edit: Just to add as a warning, if performance is a concern, you should know that using wild cards in that way is inefficient as you will end up going through large amount of the index to find matching terms. A more efficient way to do prefix and suffix search would be to use the edgeNGram tokenizer at indexing time to create various tokens that represent the beginning or the end of your words. For more details, you can look into the custom analyzer documentation : https://docs.microsoft.com/en-us/azure/search/index-add-custom-analyzers