New Feature: search with boolean operators #2293
Closed
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.
Description of the Change
Introduces a new feature to allow using Boolean Search Operators such as
+ | - () * ~N
in search queries.This is an optional feature and should be disabled when first introduced. Users can opt-in to the feature globally using the ElasticPress Features dashboard, or on individual queries by setting
$wp_query->ep_boolean_operators = true
.When activated, the feature hooks into
ep_formatted_args_query
and replaces the defaultmulti_match
queries with Elasticsearch nativesimple_query_string
queries.Syntax
To use one of these characters literally, escape it with a preceding backslash ().
This implementation also detects the use of uppercase
AND
,OR
andNOT
queries and replaces them with their proper counterparts:+
,|
and-
when preparing the ES query. If no boolean operators are found in the search text, the feature is not activated and the query continues as a regular ElasticPress query.Benefits
simple_query_string
queries are transformed internally intomatch_phrase
queries. This allows for easier control of phrase matches using "google-like" queries (such as using quotes for phrases), as well as for more "academic-like" queries to be used in museums, libraries, or just to allow more control, while still allowing for the power ofmatch
queries to find partial results, fuzziness and slop, among other features.Includes direct filters to change the most important top-level parameters as well as a catch-all filter allowing the query to be freely modified.
Possible Drawbacks
None. This feature is opt-in and will be inactive unless explicitly required.
Checklist:
Applicable Issues
Fixes: #2039
Changelog Entry
Added: Feature - Search with Boolean Operators