0

We are using Azure Search Index for one of our Search API. We have a field in Azure Search Index say Display Name (which is a string field. The requirement is from the API when we do a search using the Display Name, the search should be an exact search against the fields.

Eg: If we search for "George Joseph", the Search Index should return only records that exactly match the Display Name as "George Joseph" and it should not return records with names - "George Joseph John" or John George Joseph"

Is there any way I can accomplish this?

Regards,

John

Silly John
  • 1,584
  • 2
  • 16
  • 34
  • 1
    Just thinking out loud, can you use `filter` instead of using `search`? So your search expression would be `$filter=DisplaName%20eq%20'George Joseph'`. – Gaurav Mantri Jun 19 '17 at 15:19
  • Will it support collection of display names? like $filter=DisplayName%20eq%20'George Joseph'&DisplayName%20eq%20'George John' – Silly John Jun 19 '17 at 15:36
  • Also, we need to have the same feature to be implemented for Person's Educational qualification which is a collection. That can have "Bachelor Desgree", "Master Degree" etc. Is that possible to do that in this case? – Silly John Jun 19 '17 at 15:45
  • 1
    Why not? It's an ODATA filter query so you would construct it something like `$filter=DisplayName%20eq%20'George Joseph'%20or%20DisplayName%20eq%20'George John'`. Please see this link for more details: https://learn.microsoft.com/en-us/rest/api/searchservice/odata-expression-syntax-for-azure-search. Only catch is that the fields on which you're filtering must have `filterable` attribute set. – Gaurav Mantri Jun 19 '17 at 15:48
  • 1
    The other catch is that $filter is case-sensitive. – Bruce Johnston Jun 19 '17 at 16:30

2 Answers2

0

You can use a filter to achieve this, assuming you are interested in case-sensitive matches. For example, DisplayName eq 'George Joseph' will match exactly George Joseph but will not match george JOSEPH. You can find details about the filter syntax here.

Bruce Johnston
  • 8,344
  • 3
  • 32
  • 42
0

You can specify "&searchMode=All"

When you set searchMode=all you tell the search engine that all query terms must be matched at least once in the document-

agency temps&$count=true&$top=30&$skip=0&searchMode=All&$filter=(CompanyCode eq '13453' and VNumber eq '00023232312016') &scoringProfile=BusinessProfile1&searchFields=VCategory

https://learn.microsoft.com/en-us/azure/search/query-lucene-syntax

The searchMode=all parameter is relevant in this example. Whenever operators are on the query, you should generally set searchMode=all to ensure that all of the criteria is matched.

GET /indexes/hotels/docs?search=category:budget AND "recently renovated"^3&searchMode=all&api-version=2020-06-30&querytype=full

dewraj singh
  • 128
  • 1
  • 10