Skip to content
Justin edited this page May 30, 2019 · 8 revisions

Available filters:

solr_scheme

Filters the schema used to connect to the solr server (http/https).

function filter_solr_scheme( $scheme ) {
	// set $scheme as required.
	return $scheme;
}
add_filter( 'solr_scheme', 'filter_solr_scheme', 10, 1 );

s4wp_connection_options

Filters connection options for the solr server.

function filter_s4wp_connection_options( $solarium_config ) {
	// set $solarium_config as required.
	// Ex: $solarium_config['endpoint']['localhost']['host'] = '127.0.0.1'
	return $solarium_config;
}
add_filter( 's4wp_connection_options', 'filter_s4wp_connection_options', 10, 1 );

s4wp_solr

Replace the solarium client with a custom client.

function filter_s4wp_solr( $solarium_client ) {
	// set solarium client as required.
	return $solarium_client;
}
add_filter( 's4wp_solr', 'filter_s4wp_solr', 10, 1 );

solr_facet_custom_fields

Filter the list of custom field slugs available to index.

function filter_solr_facet_custom_fields( $facet_on_custom_fields ) {
	// set custom field for facet
	return $facet_on_custom_fields;
}
add_filter( 'solr_facet_custom_fields', 'filter_solr_facet_custom_fields', 10, 1 );

solr_query

Filter the Solarium query object.

function filter_solr_query( $query ) {
	// alter Solarium query object
	return $query;
}
add_filter( 'solr_query', 'filter_solr_query', 10, 1 );

solr_facet_items

Filter the HTML output of a facet in facet widget.

function filter_solr_facet_items( $html, $facet_name, $data ) {
	/*
	* Default value passed is false.
	* return html of a facet item.
	*/
	return $html;
}
add_filter( 'solr_facet_items', 'filter_solr_facet_items', 10, 3 );

solr_facet_title

Filter the facet title displayed in the widget.

function filter_solr_facet_title( $title, $facet_name ) {
	/*
	* Default value passed is false.
	* return title of a facet.
	*/
	return $title;
}
add_filter( 'solr_facet_title', 'filter_solr_facet_title', 10, 2 );

solr_facet_searchbox

Filter the HTML output of the facet widget search box.

function filter_solr_facet_searchbox( $html ) {
	// html for searchbox
	return $html;
}
add_filter( 'solr_facet_searchbox', 'filter_solr_facet_searchbox', 10, 1 );

solr_index_custom_fields

Filter the list of custom field slugs available to index.

function filter_solr_index_custom_fields( $custom_fields ) {
	// alter the list of custom fields for indexing
	return $custom_fields;
}
add_filter( 'solr_index_custom_fields', 'filter_solr_index_custom_fields', 10, 1 );

solr_post_types

Filter the list of post types available to index.

function filter_solr_post_types( $post_types ) {
	// Filter indexable post types
	return $post_types;
}
add_filter( 'solr_post_types', 'filter_solr_post_types', 10, 1 );

solr_allow_ajax

Filter to use ajax. By default the plugin won't query Solr on AJAX requests, set true to override.

function filter_solr_allow_ajax( $flag ) {
	// Default is false
	// return true if want to query Solr in ajax requests
	return $flag;
}
add_filter( 'solr_allow_ajax', 'filter_solr_allow_ajax', 10, 1 );

solr_allow_admin

Allow Solr Search in WordPress Dashboard, By default the plugin won't query Solr in the WordPress Dashboard, set to true to override.

function filter_solr_allow_admin( $flag ) {
	// Default is false
	// return true if want to query Solr in WordPres dashboard
	return $flag;
}
add_filter( 'solr_allow_admin', 'filter_solr_allow_admin', 10, 1 );

solr_max_search_results

Filer the maximum number of results possible from either search or WP_Query. Defaults to 50,000. Note setting post_per_page will not override this limit.

function filter_solr_max_results( $num_results ) {
	// Default is 50,000. Change $num_results to fit your needs.
	return $num_results;
}
add_filter( 'solr_max_search_results', 'filter_solr_max_results', 10, 1 );

solr_build_document

Filter the generated Solr document. @param object $doc Generated Solr document. @param object $post_info Original post object.

function filter_solr_build_document( $doc, $post_info ) {
	$doc->addField( 'my_field_key', $my_field_value );

	return $doc;
}

add_filter( 'solr_build_document', 'filter_solr_build_document', 10, 2 );

solr_post_status

Filter the post status(es) indexed by Solr. @param array $post_statuses post statuses indexed by Solr.

function filter_solr_post_statuses( $post_statuses ) {
	return array_push( $post_statuses, 'draft' );
}

add_filter( 'solr_post_status', 'filter_solr_post_statuses', 10, 1 );

solr_boost_query

Filter the fields boosted Solr. Defaults is post_title^2 post_content^1.2 @param string $solr_boost_query String of items, with their boost applied.

function filter_solr_boost_query( $solr_boost_query ) {
	return 'post_author^10 post_title^25 post_content^50';
}

add_filter( 'solr_boost_query', 'filter_solr_boost_query', 10, 1 );