Solr Core Management

The msa-wp-solr plugin is an integration of the Solarium library into a custom wp plugin.

Plugin File: solr-search.php

Plugin manifest.

require_once( SOLR_SEARCH . '/vendor/autoload.php' );

*// Load plugin class files*
require_once( 'includes/class-solr-search.php' );
require_once( 'includes/class-solr-search-settings.php' );

*// Load plugin libraries*
require_once( 'includes/class-solr-search-admin-api.php' );
require_once( 'classes/class-solr-search-solr-connector.php' );

Initializes Plugin:

$instance = Solr_Search::instance( __FILE__, '1.0.0' );

if ( is_null( $instance->settings ) ) {
$instance->settings = Solr_Search_Settings::instance( $instance );
if ( is_null( $instance->solr_client ) ) {
$instance->solr_client = new Solr_Search_Connector();

Solr_Search (class-solr-search.php)

Indexing Cores

  • add_filter('solr_reindex_core',array($this,'solrReindexCore'),10,1);
  • add_filter('solr_create_new_core',array($this,'solrCreateCore'),10,1);

mzd☯ artichoke :>grep -rn solr_reindex_core .

  • ./msa-capitol-monitor/includes/class-msa-user.php:60: reindexSolrCore():$solr_result = apply_filters( 'solr_reindex_core', 3 );
  • ./msa-feed-parser/cron_solr_mail.php:683: $solr_result = apply_filters( 'solr_reindex_core', $client );
  • ./msa-feed-parser/cron_solr_mail.php:700: $solr_result = apply_filters( 'solr_reindex_core', null );


Sets plugin environment variables: file; dir; assets-dir; assets-url;

Registers wp actions to engue front-end and admin scripts and style-assets.

Registers wp filters (services):

//adding global plugin filter
//Exposing filters for other plugins
add_filter('solr_get_legislations',array( $this, 'getLegislations' ),10,9);
add_filter('solr_get_hearings',array( $this, 'getHearings' ),10,8);

add_filter('solr_get_dashboard_main',array($this,'getDashboardMain'),10,6);     add_filter('solr_update_document_priority',array($this,'updateDocumentPriority'),10,3);

Solr_Client (class-solr-search-solr-connector.php)

Not to be confused with Solarium\Core\Client, which is added to the connector as $this->client (in createCore()).

querySolr() & querySolrDashboardMain()

The DashboardMain variant provides the counts for the map. The functions obviously share a copy-paste ancestry. But the functionality they provide is quite different.

This is the query dispatcher that accepts the query parameters and uses the Solarium\Client to communicate to the end-point (core).

Core Management

setEndPoint( $client_id )

Returns a configuration (php array) object using the plugin configuration settings and a passed Client-id.

path = '/solr/' . $this->core_prefix . $client_id;

createCore( $client_id )

TODO: why doesn't this use setEndPoint()??

reindexCore( $core )

Notable Utilities


Updates search index when a bill is prioritized. Called (indirectly) in class-msa-user.php and class-msa-client.php (msa-capitol-monitor plugin).

// get an update query instance
$update = $this->client->createUpdate();
$doc = $update->createDocument();
$doc->setKey( 'id', $id );
$doc->setField( 'priority', $priority );
$doc->setFieldModifier( 'priority', 'set' );
//add document and commit
$update->addDocument( $doc )->addCommit();

Ensures that excluded Categories as configured for the user (/client) are excluded from queries.

TODO: what about excluded states and keywords??

TODO: this function wraps some complex syntax and is used in several places. However, we are lacking encapsulation of business logic to ensure user-settings are always respected. Refactor this bad-boy.


Returns a number of upcoming hearings.

TODO: filters by states and categories, but not keywords.


Maps bill-statuses to simplified and normalized 10-step.


Provides search sugestions.

pingCore( $client_id )

Confirms core is available. Wrapped (several times!), ultimately used as MSAClient::solr_active, most often in the child-class MSAUser.