Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Feature: search with boolean operators #2293

Closed

Conversation

moraleida
Copy link
Contributor

@moraleida moraleida commented Aug 5, 2021

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 default multi_match queries with Elasticsearch native simple_query_string queries.

Syntax

  • + signifies AND operation
  • | signifies OR operation
  • - negates a single token
  • " wraps a number of tokens to signify a phrase for searching
  • * at the end of a term signifies a prefix query
  • ( and ) signify precedence
  • ~N after a word signifies edit distance (fuzziness)
  • ~N after a phrase signifies slop amount

To use one of these characters literally, escape it with a preceding backslash ().

This implementation also detects the use of uppercase AND, OR and NOT 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 into match_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 of match 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:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

Applicable Issues

Fixes: #2039

Changelog Entry

Added: Feature - Search with Boolean Operators

@moraleida moraleida marked this pull request as ready for review August 12, 2021 02:48
@moraleida moraleida changed the title Draft: New Feature: search with boolean operators New Feature: search with boolean operators Aug 12, 2021
@mckdemps mckdemps added this to the 3.7.0 milestone Aug 17, 2021
@mckdemps
Copy link
Contributor

We are integrating that code on ElasticPress Labs and it will be published on the main plugin at a later point.

@Rahmon
Copy link
Contributor

Rahmon commented Aug 20, 2021

Closing in favor of 10up/ElasticPressLabs#3

@Rahmon Rahmon closed this Aug 20, 2021
@felipeelia felipeelia modified the milestones: 3.7.0, 4.0.0 Oct 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Search exact phrase when using quotes
4 participants