/** * 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']; } }
function wdm_return_solr_rows() { if (isset($_POST['security']) && wp_verify_nonce($_POST['security'], 'nonce_for_autocomplete')) { $input = isset($_POST['word']) ? $_POST['word'] : ''; if ('' != $input) { $input = strtolower($input); try { $result = WPSOLR_Global::getSolrClient()->get_suggestions($input); echo json_encode($result); } catch (Exception $e) { echo json_encode(array('message' => htmlentities($e->getMessage()))); } } } die; }
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; }
function get_posts() { //return parent::get_posts(); // Let WP extract parameters $this->parse_query(); // Copy WP standard query to WPSOLR query $this->set_wpsolr_query($this->query[WPSOLR_Query_Parameters::SEARCH_PARAMETER_S]); // Copy WP standard paged to WPSOLR paged $this->set_wpsolr_paged(isset($this->query_vars['paged']) ? $this->query_vars['paged'] : 1); // $_GET['s'] is used internally by some themes //$_GET['s'] = $query; // Set variable 's', so that get_search_query() and other standard WP_Query methods still work with our own search parameter //$this->set( 's', $query ); $this->solr_client = WPSOLR_Global::getSolrClient(); $this->resultSet = $this->solr_client->execute_wpsolr_query($this); // Fetch all posts from the documents ids, in ONE call. $posts_ids = array(); foreach ($this->resultSet as $document) { array_push($posts_ids, $document->id); } $posts_in_results = count($posts_ids) > 0 ? get_posts(array('numberposts' => count($posts_ids), 'post_type' => 'any', 'post_status' => 'any', 'post__in' => $posts_ids)) : array(); foreach ($posts_in_results as $post) { $this->set_the_title($post); $this->set_the_excerpt($post); } $this->posts = $posts_in_results; $this->post_count = count($this->posts); $this->found_posts = $this->resultSet->getNumFound(); $this->posts_per_page = $this->get_nb_results_by_page(); $this->set("posts_per_page", $this->posts_per_page); $this->max_num_pages = ceil($this->found_posts / $this->posts_per_page); if (!isset($this->query_vars['name'])) { // Prevent error later in WP code $this->query_vars['name'] = ''; } return $this->posts; }
function get_posts() { //return parent::get_posts(); // Let WP extract parameters $this->parse_query(); $q =& $this->query_vars; $this->parse_search($q); // Copy WP standard query to WPSOLR query $this->set_wpsolr_query($this->query[WPSOLR_Query_Parameters::SEARCH_PARAMETER_S]); // Copy WP standard paged to WPSOLR paged $this->set_wpsolr_paged(isset($this->query_vars['paged']) ? $this->query_vars['paged'] : 1); // $_GET['s'] is used internally by some themes //$_GET['s'] = $query; // Set variable 's', so that get_search_query() and other standard WP_Query methods still work with our own search parameter //$this->set( 's', $query ); $this->solr_client = WPSOLR_Global::getSolrClient(); $this->resultSet = $this->solr_client->execute_wpsolr_query($this); // Create posts from Solr PIDs $posts_in_results = $this->solr_client->get_posts_from_pids(); foreach ($posts_in_results as $post) { $this->set_the_title($post); $this->set_the_excerpt($post); } $this->posts = $posts_in_results; $this->post_count = count($this->posts); $this->found_posts = $this->resultSet->getNumFound(); $this->posts_per_page = $this->get_nb_results_by_page(); $this->set("posts_per_page", $this->posts_per_page); $this->max_num_pages = ceil($this->found_posts / $this->posts_per_page); if (!isset($this->query_vars['name'])) { // Prevent error later in WP code $this->query_vars['name'] = ''; } return $this->posts; }
/** * 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); }