10up / ElasticPress

A fast and flexible search and query engine for WordPress.
https://elasticpress.io
GNU General Public License v2.0
1.24k stars 312 forks source link

BUG? Different Custom Search Results should not interfere with each other. #2180

Open felipeelia opened 3 years ago

felipeelia commented 3 years ago

Describe the bug

If a user has two different Custom Search Results and one is a substring of the other, results in the smaller one will appear in the longest one.

Example: "Dental Real Estate Purchases" and "Real Estate". While searching for "Real Estate", the results added to "Dental Real Estate Purchases" will show up as "Real Estate" matches the search term.

Steps to Reproduce

  1. Create two different CSR: "Dental Real Estate Purchases" and "Real Estate"
  2. Add a post to "Dental Real Estate Purchases"
  3. Search for "Real Estate"
  4. See the post added to "Dental Real Estate Purchases" in the results

Expected behavior

Should the results added to one CSR be displayed in another one?

airportjule commented 3 years ago

Thanks Felipe.

For added clarification, in the given example the results for "Dental Real Estate Purchases" are "people" Posts and are mainly associated with dentistry; not Real Estate. So when they appear at the top of a search for "Real Estate" the results are inaccurately ranking higher than other posts more relevant to the Real Estate concept itself.

felipeelia commented 3 years ago

To avoid this issue we'll have to make some changes to the plugin:

  1. Add an option in the Custom Search Results (CSR) feature to enable/disable this different behavior
  2. If the user decides to enable it, the terms.ep_custom_result.name should be treated differently, just accepting exact matches.

In the meantime, this is a way to work around it:

CSRs rely on a taxonomy called ep_custom_result, so every new CSR is a term of that taxonomy, and posts are added to that term. So, first, it'll be needed to disable the \Feature\SearchOrdering::filter_weighting_configuration() method, so EP won't use the term field in its search. Then hook a new function to posts_results, to manually add all posts in that term to the search results.

Thanks again for bringing it up @airportjule! And feel free to share anything you think will be helpful for future users having the same issue.

airportjule commented 3 years ago

Does this workaround limit only CSR terms from affecting search results, or disable all weighting configuration?