0
votes

Our service's default search web page uses the * full Lucene query to match all documents. This is before the user has provided any search terms. There is some data (test data, in our case) that we want to exclude from the search result.

Is it possible to match all documents but exclude a subset of all documents?

For example, suppose we have an "owners" field and we want to exclude documents with the "testA" and "testB" owner. The following query does not seem to work with the match all approach:

Query:  search=* -owners:testA -owners:testB&queryType=full&$orderby=created desc
Error:  "Failed to parse query string. See https://aka.ms/azure-search-full-query for supported syntax."

When searching for anything but *, this approach works fine. For example:

Query:  search=foo -owners:testA -owners:testB&queryType=full&$orderby=created desc
Result: (many documents matched)

I have considered a $filter for this and using $filter=filterableOwners/all(p: p ne 'testa' and p ne 'testb') but this has the following drawbacks:

  • the index must be rebuild with a filterable field
  • analyzers can't be used so case-insensitivity must be implemented by lowercasing the values and filter expression

Ideally this could be done using only the search query parameter with a Lucene query text.

1

1 Answers

0
votes

I found a workaround for the issue. If you have a field in your documents that always has a value, you can use a .* regex to match all values in the field and therefore match all documents.

For example, suppose the packageId field has a value for all documents.

Incorrect (as posted in the original question):

Query:  search=* -owners:testA -owners:testB&queryType=full&$orderby=created desc

Correct:

Query:  search=packageId:/.*/ -owners:testA -owners:testB&queryType=full&$orderby=created desc