/** * simple search with an operator and words * * @param string $operator 'And' or 'Or' default : 'Or' * @param string $words data * @param integer $start the begining of the paging * @param integer $limit the interval of the paging * @param array $names_types the restrictive type(s) where the search take place. * @param bool $aggregation parameter the search to be aggregated or not. * * @return \Elastica\ResultSet */ function searchQueryString($operator, $words, $start = 0, $limit = 30, $names_types = null, $aggregation = false) { $words = CSearch::normalizeEncoding($words); // Define a Query. We want a string query. $queryString = new Elastica\Query\QueryString($words); $queryString->setDefaultOperator("and"); // Create the actual search object with some data. $query = new Elastica\Query($queryString); //create aggregation if ($aggregation) { // on aggrège d'abord par class d'object référents // on effectue un sous aggrégation par id des objets référents. $agg_by_date = new CSearchAggregation("Terms", "date_log", "date", 10); $sub_agg_by_user = new CSearchAggregation("Terms", "user_id", "user_id", 10); $sub_agg_by_contexte = new CSearchAggregation("Terms", "contexte", "_type", 10); $sub_agg_by_user->_aggregation->addAggregation($sub_agg_by_contexte->_aggregation); $agg_by_date->_aggregation->addAggregation($sub_agg_by_user->_aggregation); $query->addAggregation($agg_by_date->_aggregation); } else { // Pagination $query->setFrom($start); // Where to start $query->setLimit($limit); } //Highlight $query->setHighlight(array("fields" => array("body" => array("pre_tags" => array(" <em> <strong> "), "post_tags" => array(" </strong> </em>"), "fragment_size" => 80, "number_of_fragments" => 10)))); //Search on the index. $index = CAppUI::conf("search index_name") . "_log"; $index = $this->loadIndex($index); $search = new \Elastica\Search($this->_client); $search->addIndex($index); if ($names_types) { $search->addTypes($names_types); } return $search->search($query); }