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 60 forks source link

Custom ACF field with boost #488

Open greenSkin opened 3 years ago

greenSkin commented 3 years ago

I'm trying to use a custom ACF field as a boost keyword field. I'm looking to raise posts to the top of search results based on matches in this field. I've tried using the solr_index_custom_fields and solr_boost_query filters but have had no luck. Please help!

danielbachhuber commented 3 years ago

Hi @greenSkin 👋

Can you share the code snippets you've tried? Also, is this a site hosted on Pantheon?

greenSkin commented 3 years ago

Yes, the site is hosted on Pantheon. I've tried a few different things. The simplest was the following:

add_filter( 'solr_index_custom_fields', function( $indexed_keys ) {
    $indexed_keys[] = 'solr_search_boost';

    return $indexed_keys;
} );

add_filter( 'solr_boost_query', function( $solr_boost_query ) {
    return 'post_title^2 post_content^1.2 solr_search_boost^5';
} );

The solr_search_boost is the field name of my simple ACF text field. Also, when I include "solr_search_boost^5" in the 'solr_boost_query" filter I get 0 search results, even after re-indexing.

danielbachhuber commented 3 years ago

Oh! You might've been bit by #359 too.

Solr Power doesn't search against the post meta value by default, so you need to do some code trickery to make that happen.

When boosting, I think you'll need to use solr_search_boost_str, which is the name of the field as Solr knows it.

Can you try those out and let me know how you progress?

greenSkin commented 3 years ago

Thanks. I applied #359 solution and it seems to help but I'm still not able to get the boost working. I set the boost to post_title^2 post_content^1.2 solr_search_boost_str^5 but even that ends up giving me 0 results for queries that would have otherwise given results.