Search query for empty\null string field in Azure search
Asked Answered
E

1

6

Hi I have a string field which can be empty\null for certain documents. I like to know how to search for those documents.

I want to know thru searchquery and not ODatFilter as I may like to solve following cases:

  1. searching for empty\null in this field A
  2. searching for substring in this field A( Eg: A:test)
  3. searching for both empty\null or values containing test.

So ODataFilter suggestions will not help in achieving #2 so #1 should be using searchQuery.

Any help is appreciated.

Entire answered 13/4, 2020 at 23:49 Comment(0)
B
7

You can actually combine OData filters with search queries using the search.ismatch or search.ismatchscoring functions. These functions let you embed full-text search queries inside a filter, which would allow you to address all your scenarios:

  1. $filter=A ne null
  2. $filter=A ne null and search.ismatchscoring('A:test', null, 'full', null) or equivalently, $filter=A ne null&search=A:test&queryType=full
  3. $filter=A eq null or search.ismatchscoring('A:test', null, 'full', null) -- this can only be achieved with filters and search.ismatch/search.ismatchscoring because of the "or" operator.

The filter A ne null in case 2 above is actually redundant since nulls won't match any full-text search query, but in case 3 where you want to match nulls, filters are the way to do it.

Bhagavadgita answered 20/4, 2020 at 18:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.