Пример #1
0
 public function actionList($status, $flags, $q)
 {
     if ($status) {
         $this->songy = $this->songList->findByStatus($status);
     } else {
         $this->songy = $this->songList->findAll();
     }
     //Simple song searching
     if ($q) {
         $searcher = new \Searcher();
         $searcher->setModel($this->songy);
         $searcher->setMask("%?%");
         $searcher->setColumns(array("name", "interpret_name"));
         $searcher->search($q);
         $this->template->q = $q;
     }
     //Filtering by flags
     if ($flags) {
         $this->setFilterDefaults($flags);
         $filter = new \FlagFilter();
         $filter->setModel($this->songy);
         $filter->setFlags(array("r" => "remix", "i" => "instro", "p" => "pecka", "w" => "wishlist_only", "n" => array("column" => "note", "by" => " != ''")));
         $filter->filter($flags);
     }
     //Store list page and filtering
     $this->getSession()->getSection("SongList")->listing = $this->getHttpRequest()->getQuery();
     $this->template->summary = $this->songList->getSummary();
     $this->template->status = $status;
 }
 function do_search($wp_query)
 {
     if (!$wp_query->is_main_query() || is_admin() || $this->attempted) {
         return;
     }
     $this->attempted = true;
     $args = $this->facets($wp_query, isset($_GET['es']) ? $_GET['es'] : array());
     if ($args === null) {
         return;
     }
     $this->page = isset($wp_query->query_vars['paged']) && $wp_query->query_vars['paged'] > 0 ? $wp_query->query_vars['paged'] - 1 : 0;
     if (!isset($wp_query->query_vars['posts_per_page'])) {
         $wp_query->query_vars['posts_per_page'] = get_option('posts_per_page');
     }
     $this->search = isset($wp_query->query_vars['s']) ? urldecode(str_replace('\\"', '"', $wp_query->query_vars['s'])) : '';
     $results = Searcher::search($this->search, $this->page, $wp_query->query_vars['posts_per_page'], $args, $this->search ? false : true);
     if ($results == null) {
         return null;
     }
     $this->total = $results['total'];
     $this->ids = $results['ids'];
     $wp_query->query_vars['s'] = '';
     # do not show results if none were returned
     $wp_query->query_vars['post__in'] = empty($results['ids']) ? array(0) : $results['ids'];
     $wp_query->query_vars['paged'] = 1;
     $wp_query->facets = $results['facets'];
     $this->searched = true;
 }
Пример #3
0
 public function testSearch()
 {
     $account = Account::login("searchzen.org", "test");
     $collection = $account->collections[0];
     $searcher = new Searcher($collection);
     $results = $searcher->search("Jacob", 0);
 }
Пример #4
0
 public function search($domain, $query)
 {
     $searcher = new Searcher($this->getAccountId($domain));
     return $searcher->search($query, 0);
 }
Пример #5
0
        }
        $this->pos = 0;
        $this->num = 0;
    }
}
// main
$searcher = new Searcher();
$input = new Input();
$output = null;
$count = 0;
try {
    $searcher->setInput($input);
    $db = OnyokuDB::getInstance();
    if ($count = $searcher->count($db)) {
        // ヒットした件数
        $searcher->search($db);
    }
    $output = $searcher->export();
} catch (Exception $e) {
    $error_message = $e->getMessage();
}
$result['results'] = $count;
if ($output) {
    $tmp = json_decode($output, true);
    for ($i = 0; $i < $count; $i++) {
        $a['name'] = $tmp['data'][$i][0];
        if ($input->mode == 'artist' || $input->mode == 'label') {
            $a['kana'] = $tmp['data'][$i][1];
            $a['id'] = $tmp['data'][$i][2];
        } else {
            if ($input->mode == 'category' || $input->mode == 'music' || $input->mode == 'disc_type') {
Пример #6
0
 function get_posts_from_elasticsearch($wp_query)
 {
     $this->search_successful = false;
     if (function_exists('is_main_query') && !$wp_query->is_main_query()) {
         return;
     }
     if (is_search() && !is_admin()) {
         try {
             global $query_string;
             global $elasticaFacets;
             $offset = 0;
             if (get_query_var('page') != "") {
                 $offset = (max(1, get_query_var('page')) - 1) * 4;
             }
             $limit = 4;
             require_once "lib" . DIRECTORY_SEPARATOR . "Searcher.php";
             $searcher = new Searcher(get_option('elasticsearch_settings_server'));
             $facetArr = array();
             if (get_option('elasticsearch_result_category_facet')) {
                 array_push($facetArr, 'cats');
             }
             if (get_option('elasticsearch_result_tags_facet')) {
                 array_push($facetArr, 'tags');
             }
             if (get_option('elasticsearch_result_author_facet')) {
                 array_push($facetArr, 'author');
             }
             if (get_option('elasticsearch_result_date_facet')) {
                 array_push($facetArr, 'date');
             }
             $page = get_query_var('paged');
             $offset = 0;
             if ($page > 0) {
                 $offset = ($page - 1) * $this->per_page;
             }
             //In order to use search for specfic index type, give that type to 6th parameter
             $search_results = $searcher->search($_GET, $facetArr, $offset, $this->per_page, get_option('elasticsearch_settings_index_name'), false);
             $search_result_count = $searcher->search($_GET, $facetArr, false, false, get_option('elasticsearch_settings_index_name'), false)->count();
             $elasticsearch_post_ids = array();
             $records = $search_results->getResults();
             foreach ($records as $record) {
                 $elasticsearch_post_ids[] = substr($record->getId(), 5);
             }
             $this->total_num_results = $search_result_count;
             $this->post_ids = $elasticsearch_post_ids;
             $wp_query->query_vars['post__in'] = $this->post_ids;
             $wp_query->query_vars['posts_per_page'] = -1;
             unset($wp_query->query_vars['author']);
             unset($wp_query->query_vars['title']);
             unset($wp_query->query_vars['content']);
             $wp_query->query_vars['s'] = str_replace("*", "", $wp_query->query_vars['s']);
             $elasticaFacets = $search_results->getFacets();
             $this->search_successful = true;
         } catch (Exception $e) {
             $this->search_successful = true;
             error_log("Can not connect to elasticsearch " + $e);
         }
     }
 }