pantheon-systems / solr-power

A WordPress plugin to connect to Pantheon's Apache Solr search infrastructure, or your own!
https://wordpress.org/plugins/solr-power/
GNU General Public License v2.0
126 stars 61 forks source link

Facet query parsing probably shouldn't use default operator #385

Closed mgburns closed 6 years ago

mgburns commented 6 years ago

In line 436 of class-solrpower-wp-query.php the default query operator is used to join facet clauses.

This feels conflated to me, as the search operator for multi-word queries feels very different than the search operator for facet queries. Take the following psuedo-query:

Query: how do I apply to college filtered by post type faq from date 2018.

If the default search operator is OR, then it will find posts that have any of the query words present, that have either a post type of faq or were published in 2018.

In our UI, and for most I would imagine, I would expect the filters to be joined with an AND instead of an OR, but I also don't want to be overly strict with multi-phrase query terms.

I'd think the default join op for facets should be AND (perhaps filterable with apply_filters).

ataylorme commented 6 years ago

For backwards compatibility we could do something like this:

$default_operator = ( isset( $plugin_s4wp_settings['s4wp_default_operator'] ) ) ? $plugin_s4wp_settings['s4wp_default_operator'] : 'OR';
$facet_operator = apply_filters( 'solr_facet_operator', $default_operator );

and then use $facet_operator instead of $default_operator in the return statements of parse_facets.

This would allow you to change the facet operator with a filter without changing existing functionality for those not expecting the change.

Would that work for you @mgburns?

mgburns commented 6 years ago

Totally! Thanks @ataylorme.

ataylorme commented 6 years ago

@mgburns feel free to make a PR, especially if you are participating in Hacktoberfest, otherwise, I'll make a PR when I have some time next week.

mgburns commented 6 years ago

@ataylorme Wait, I can get a free T-Shirt?? Count me in! :)