示例#1
0
 /**
  * method to search log details
  *
  * @param string $operator    the operator for the query
  * @param string $words       the words
  * @param string $names_types the types to search
  *
  * @return \Elastica\ResultSet
  */
 function searchQueryLogDetails($operator, $words, $names_types = null)
 {
     $words = CmbString::normalizeUtf8(stripcslashes($words));
     // Define a Query. We want a string query.
     $elasticaQueryString = new QueryString();
     //'And' or 'Or' default : 'Or'
     $elasticaQueryString->setDefaultOperator($operator);
     $elasticaQueryString->setQuery($words);
     // Create the actual search object with some data.
     $elasticaQuery = new Query();
     $elasticaQuery->setQuery($elasticaQueryString);
     //Search on the index.
     $index = CAppUI::conf("search index_name") . "_log";
     $this->_index = $this->loadIndex($index);
     $search = new \Elastica\Search($this->_client);
     $search->addIndex($this->_index);
     if ($names_types) {
         $search->addTypes($names_types);
     }
     $elasticaQuery->setFrom(0);
     // Where to start
     $elasticaQuery->setLimit(1000);
     return $search->search($elasticaQuery);
 }
示例#2
0
 /**
  * simple search
  *
  * @param string  $words     data
  * @param integer $start     the begining of the paging
  * @param integer $limit     the interval of the paging
  * @param integer $sejour_id the id of the sejour
  *
  * @return \Elastica\Query
  */
 function searchQueryStringManual($words, $start, $limit, $sejour_id)
 {
     $words = CmbString::normalizeUtf8(stripcslashes($words));
     $sejour = $this->constructWordsWithSejour($sejour_id);
     $query_bool = new Elastica\Query\Bool();
     // Query words
     $query_words = new Elastica\Query\QueryString();
     $query_words->setQuery($words);
     $query_words->setFields(array("body", "title"));
     $query_words->setDefaultOperator("and");
     $query_bool->addMust($query_words);
     // Query Séjour
     $query_sejour = new Elastica\Query\QueryString();
     $query_sejour->setQuery($sejour);
     $query_sejour->setDefaultOperator("and");
     $query_bool->addMust($query_sejour);
     $query = new Query($query_bool);
     //Pagination
     $query->setFrom($start);
     // Where to start
     $query->setLimit($limit);
     //Highlight
     if ($words) {
         $query->setHighlight(array("pre_tags" => array(" <em> <strong> "), "post_tags" => array(" </strong> </em>"), "fields" => array("body" => array("fragment_size" => 50, "number_of_fragments" => 3, "highlight_query" => array("bool" => array("must" => array("match" => array("body" => array("query" => $words))), "minimum_should_match" => 1))))));
     }
     return $query;
 }