setRemoveWordsIfNoResults method

AlgoliaQuery setRemoveWordsIfNoResults(
  1. RemoveWordsIfNoResults value
)

RemoveWordsIfNoResults

Selects a strategy to remove words from the query when it doesn’t match any hits.

The goal is to avoid empty results by progressively loosening the query until hits are matched. You can learn more about this technique, as well as caveats with non-alphanumeric characters, in our in-depth guide on removing words to improve results.

Options:

  • none: No specific processing is done when a query does not return any results (default behavior).
  • lastWords: When a query does not return any results, treat the last word as optional. The process is repeated with words N-1, N-2, etc. until there are results, or at most 5 words have been removed.
  • firstWords: When a query does not return any results, treat the first word as optional. The process is repeated with words 2, 3, etc. until there are results, or at most 5 words have been removed.
  • allOptional: When a query does not return any results, make a second attempt treating all words as optional. This is equivalent to transforming the implicit AND operator applied between query words to an OR.

Source: Learn more

Implementation

AlgoliaQuery setRemoveWordsIfNoResults(RemoveWordsIfNoResults value) {
  assert(!_parameters.containsKey('removeWordsIfNoResults'));
  return _copyWithParameters(<String, dynamic>{
    'removeWordsIfNoResults': value.toString().split('.').last
  });
}