Introduce the filter syntax for CONTAINS
, STARTS
and ENDS WITH
#3751
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces three filters. These filters give more control over the facet string values, with can be powerful in certain situations. Keep in mind that there are performance issues with both the
CONTAINS
andENDS WITH
filters. It is algorithmically impossible to fix theCONTAINS
one.Related to meilisearch/product#544.
Mini Spec
The
CONTAINS
filter📝 Can't be improved
CONTAINS
matches fields thatEXISTS
and contains a specific string insideNOT CONTAINS
matches fields thatNOT EXISTS
OR do not contain a specific string{"name":"A", "company": "Airbus 2000"}
{"name":"B", "company": "Tesla Inc"}
{"name":"C", "company": "Meilisearch"}
{"name":"D"}
company CONTAINS 'meilisearch'
would match 3company NOT CONTAINS "meilisearch"
orNOT company CONTAINS meilisearch
would match 1,2,4company CONTAINS a
would match 1,2,3company NOT CONTAINS microsoft
orNOT company CONTAINS microsoft
would match 1,2,3,4common query :
(company CONTAINS meilisearch) OR (company NOT EXISTS)
would match 3,4The
STARTS WITH
filter📝 Can be sped up by using the levels/layers structures
STARTS WITH
matches fields thatEXISTS
and starts with a specific string insideNOT STARTS WITH
matches fields thatNOT EXISTS
OR do not starts with a specific string{"name":"A", "company": "Airbus 2000"}
{"name":"B", "company": "Tesla Inc"}
{"name":"C", "company": "Meilisearch"}
{"name":"D"}
company STARTS WITH 'meili'
would match 3company NOT STARTS WITH "meili"
orNOT company STARTS WITH meili
would match 1,2,4company STARTS WITH a
would match 1,2,3company NOT STARTS WITH micro
orNOT company STARTS WITH micro
would match 1,2,3,4common query :
(company STARTS WITH meili) OR (company NOT EXISTS)
would match 3,4The
ENDS WITH
filter📝 Can be improved by duplicating the entire database and swap the strings chars
ENDS WITH
matches fields thatEXISTS
and ends with a specific string insideNOT ENDS WITH
matches fields thatNOT EXISTS
OR do not ends with a specific string{"name":"A", "company": "Airbus 2000"}
{"name":"B", "company": "Tesla Inc"}
{"name":"C", "company": "Meilisearch"}
{"name":"D"}
company ENDS WITH 'search'
would match 3company NOT ENDS WITH "search"
orNOT company ENDS WITH search
would match 1,2,4company ENDS WITH a
would match 1,2,3company NOT ENDS WITH soft
orNOT company ENDS WITH soft
would match 1,2,3,4common query :
(company ENDS WITH search) OR (company NOT EXISTS)
would match 3,4Todo List