matchingStrategy as a search parameter to control the trade-off between returning more results (higher recall) and returning more precise results (higher precision).
Available strategies
last (default)
The last strategy drops query terms starting from the end of the query. It returns documents matching all terms first, then progressively drops the rightmost terms to find more results.
For a query like batman dark knight, this strategy returns:
- Documents matching “batman”, “dark”, and “knight”
- Documents matching “batman” and “dark”
- Documents matching “batman”
last when you want to always return results, even if the query is long or specific. This is the best choice for most search interfaces.
all
The all strategy requires every query term to be present in matching documents. If a document is missing any term, it is excluded from the results.
all when precision matters more than returning many results. This is a good choice for technical search, product catalogs with specific queries, or situations where showing irrelevant results is worse than showing fewer results.
frequency
The frequency strategy drops the most common query terms first rather than dropping from the end. It analyzes how frequently each term appears across all documents in the index and removes the most common terms to improve result relevancy.
frequency strategy drops “the” first because it is the least distinctive term.
Use frequency when your users search with natural language queries that may include common words. This strategy is particularly effective when you have not configured stop words, as it naturally de-emphasizes high-frequency terms.
Comparison
| Strategy | Drops terms from | Best for | Result count |
|---|---|---|---|
last | End of query | General search, search-as-you-type | Most results |
all | None (requires all) | Precise queries, technical search | Fewest results |
frequency | Most common first | Natural language queries | Moderate results |
Interaction with phrase search
When a query contains a phrase search (quoted terms), the phrase is always treated as a single required unit regardless of the matching strategy. The strategy only applies to non-quoted terms in the query. For example, with the query"dark knight" batman returns:
last: The phrase “dark knight” is required, “batman” may be dropped, then “returns”all: The phrase “dark knight”, “batman”, and “returns” are all requiredfrequency: The phrase “dark knight” is required, the most frequent of “batman” and “returns” may be dropped
For the full parameter reference, see the search API reference.