/** * Grab instance of object. * @return SolrPower_Api */ public static function get_instance() { if (!self::$instance) { self::$instance = new self(); } return self::$instance; }
function posts_request($request, $query) { if (!$query->is_search()) { return $request; } $solr_options = SolrPower_Options::get_instance()->get_option(); $the_page = !$query->get('paged') ? 1 : $query->get('paged'); $qry = $query->get('s'); $offset = $query->get('posts_per_page') * ($the_page - 1); $count = $query->get('posts_per_page'); $fq = array(); $sortby = isset($solr_options['s4wp_default_sort']) && !empty($solr_options['s4wp_default_sort']) ? $solr_options['s4wp_default_sort'] : 'score'; $order = 'desc'; $search = SolrPower_Api::get_instance()->query($qry, $offset, $count, $fq, $sortby, $order); if (is_null($search)) { return false; } $search = $search->getData(); $search = $search['response']; $query->found_posts = $search['numFound']; $query->max_num_pages = ceil($search['numFound'] / $query->get('posts_per_page')); $posts = array(); foreach ($search['docs'] as $post_array) { $post = new stdClass(); foreach ($post_array as $key => $value) { if ('displaydate' == $key) { $post->post_date = $value; continue; } if ('displaymodified' == $key) { $post->post_modified = $value; continue; } if ('post_date' == $key || 'post_modified' == $key) { continue; } if ('post_id' == $key) { $post->ID = $value; continue; } $post->{$key} = $value; } $post->solr = true; $posts[] = $post; } $this->found_posts[spl_object_hash($query)] = $posts; global $wpdb; return "SELECT * FROM {$wpdb->posts} WHERE 1=0"; }
function activate() { // Check to see if we have environment variables. If not, bail. If so, create the initial options. if ($errMessage = SolrPower::get_instance()->sanity_check()) { wp_die($errMessage); } // Don't try to send a schema if we're not on Pantheon servers. if (!defined('SOLR_PATH')) { $schemaSubmit = SolrPower_Api::get_instance()->submit_schema(); if (strpos($schemaSubmit, 'Error')) { wp_die('Submitting the schema failed with the message ' . $errMessage); } } SolrPower_Options::get_instance()->initalize_options(); return; }
function render() { echo '<h2>Solr Information</h2>'; $log = SolrPower_Api::get_instance()->log; echo '<table>'; foreach ($log as $label => $value) { echo '<tr>'; echo '<td><strong>' . esc_html($label) . ':</strong></td>'; if (is_array($value)) { echo '<td><ul>'; foreach ($value as $val) { echo '<li>' . esc_html($val) . '</li>'; } echo '</ul></td>'; } else { echo '<td>' . esc_html($value) . '</td>'; } echo '</tr>'; } echo '</table>'; }
/** * Test to see if we can ping the Solr server. */ function test_solr_active() { $this->assertTrue(SolrPower_Api::get_instance()->ping_server()); }
</table> </div> <?php if ($server_ping) { ?> <div class="solr-display"> <table class="widefat"> <thead> <tr> <th colspan="2"><strong>Indexing Stats by Post Type</strong></th> </tr> </thead> <tbody> <?php foreach (SolrPower_Api::get_instance()->index_stats() as $type => $stat) { ?> <tr> <td><?php echo esc_html($type); ?> :</td> <td><?php echo absint($stat); ?> </td> </tr> <?php } ?> </tbody>
/** * Tests to see if indexing stats work upon delete. * @group 40 * @link https://github.com/pantheon-systems/solr-power/issues/40 */ function test_index_stats_on_delete() { $delete_id = $this->__create_test_post('page'); $this->__create_test_post('page'); $this->__create_multiple(5); if (is_multisite()) { $blogid = get_current_blog_id(); $delete_id = $blogid . '_' . $delete_id; } // Delete all of these newly indexed items: SolrPower_Sync::get_instance()->delete($delete_id); $stats = SolrPower_Api::get_instance()->index_stats(); $this->assertEquals(1, $stats['page']); $this->assertEquals(5, $stats['post']); }
</h3> <?php // @todo add the rest of the discovered info here. ?> <pre> Solr Server IP address : <?php echo esc_html(getenv('PANTHEON_INDEX_HOST')); ?> <br /> Solr Server Port : <?php echo esc_html(getenv('PANTHEON_INDEX_PORT')); ?> <br /> Solr Server Path : <?php echo esc_html(SolrPower_Api::get_instance()->compute_path()); ?> <br /> </pre> </div> <?php $action = 'options-general.php?page=solr-power'; include 'views/options/indexing.php'; include 'views/options/action.php'; include 'views/options/query.php'; ?> </div>
/** * Run the Solr query on the options page. */ private function run_query() { $qry = filter_input(INPUT_POST, 'solrQuery', FILTER_SANITIZE_STRING); $offset = null; $count = null; $fq = null; $sortby = null; $order = null; $results = SolrPower_Api::get_instance()->query($qry, $offset, $count, $fq, $sortby, $order); if (!$results) { $this->msg = __('<p><strong>Solr Results for string "' . esc_html($qry) . ' ":</strong> <br/>Search Failed. </p>', 'solr-for-wordpress-on-pantheon'); return; } $data = $results->getData(); $response = $data['response']; $header = $data['responseHeader']; $out['hits'] = $response['numFound']; $out['qtime'] = sprintf(__("%.3f"), $header['QTime'] / 1000); $this->msg = __('<p><strong>Solr Results for string "' . esc_html($qry) . ' ":</strong> <br/>Hits: ' . esc_html($out['hits']) . ' <br/>Query Time: ' . esc_html($out['qtime']) . ' </p>', 'solr-for-wordpress-on-pantheon'); }
/** * Helper function to return Solr object. */ function get_solr() { return SolrPower_Api::get_instance()->get_solr(); }