コード例 #1
0
 public static function action_wp_loaded()
 {
     if (WPSOLR_Query_Parameters::is_wp_search() && !is_admin() && is_main_query() && WPSOLR_Global::getOption()->get_search_is_replace_default_wp_search()) {
         // Override global $wp_query with wpsolr_query
         $GLOBALS['wp_the_query'] = WPSOLR_Global::getQuery();
         $GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
     }
 }
コード例 #2
0
 /**
  * Front-end display of widget.
  *
  * @see WP_Widget::widget()
  *
  * @param array $args Widget arguments.
  * @param array $instance Saved values from database.
  */
 public function widget($args, $instance)
 {
     if (WPSOLR_Global::getOption()->get_search_is_replace_default_wp_search() && WPSOLR_Global::getOption()->get_search_is_use_current_theme_search_template() && WPSOLR_Query_Parameters::is_wp_search()) {
         echo $args['before_widget'];
         $results = WPSOLR_Global::getSolrClient()->display_results(WPSOLR_Global::getQuery());
         echo '<div id="res_facets">' . WPSOLR_UI_Facets::Build(WPSOLR_Data_Facets::get_data(WPSOLR_Global::getQuery()->get_filter_query_fields_group_by_name(), WPSOLR_Global::getOption()->get_facets_to_display(), $results[1]), OptionLocalization::get_options()) . '</div>';
         echo $args['after_widget'];
     }
 }
コード例 #3
0
function return_solr_results()
{
    $final_result = WPSOLR_Global::getSolrClient()->display_results(WPSOLR_Global::getQuery());
    // Add result rows as html
    $res1[] = $final_result[3];
    // Add pagination html
    $total = $final_result[2];
    $number_of_res = WPSOLR_Global::getOption()->get_search_max_nb_results_by_page();
    $paginat_var = '';
    if ($total > $number_of_res) {
        $pages = ceil($total / $number_of_res);
        $paginat_var .= '<ul id="pagination-flickr"class="wdm_ul">';
        for ($k = 1; $k <= $pages; $k++) {
            $paginat_var .= "<li ><a class='paginate' href='javascript:void(0)' id='{$k}'>{$k}</a></li>";
        }
        $paginat_var .= '</ul>';
    }
    $res1[] = $paginat_var;
    // Add results infos html ('showing x to y results out of n')
    $res1[] = $final_result[4];
    // Add facets data
    $res1[] = WPSOLR_UI_Facets::Build(WPSOLR_Data_Facets::get_data(WPSOLR_Global::getQuery()->get_filter_query_fields_group_by_name(), WPSOLR_Global::getOption()->get_facets_to_display(), $final_result[1]), OptionLocalization::get_options());
    // Output Json response to Ajax call
    echo json_encode($res1);
    die;
}
 /**
  * Get suggestions from Solr search.
  *
  * @param string $query Keywords to suggest from
  *
  * @return array
  */
 public function get_suggestions_posts($query)
 {
     $wpsolr_query = WPSOLR_Global::getQuery();
     $wpsolr_query->set_wpsolr_query($query);
     $results = WPSOLR_Global::getSolrClient()->display_results($wpsolr_query);
     return array_slice($results[3], 0, 5);
 }