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

Custom ACF field with boost #488

Open
greenSkin opened this issue Dec 19, 2020 · 4 comments
Open

Custom ACF field with boost #488

greenSkin opened this issue Dec 19, 2020 · 4 comments
Labels

Comments

@greenSkin
Copy link

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
Copy link
Contributor

Hi @greenSkin 👋

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

@greenSkin
Copy link
Author

greenSkin commented Dec 21, 2020

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
Copy link
Contributor

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants