Exemplo n.º 1
0
 /**
  * @group unit
  */
 public function testSetRescoreToArrayCast()
 {
     $query = new Query();
     $rescore = new \Elastica\Rescore\Query();
     $rescore->setQueryWeight(1);
     $query->setRescore($rescore);
     $rescore->setQueryWeight(2);
     $anotherQuery = new Query();
     $anotherQuery->setRescore($rescore);
     $this->assertEquals($query->toArray(), $anotherQuery->toArray());
 }
Exemplo n.º 2
0
 /**
  * @param mixed  $query
  * @param string $type
  *
  * @return mixed|void
  */
 public function defineSearch($query, $type)
 {
     $query = \Elastica\Util::escapeTerm($query);
     $elasticaQueryString = new \Elastica\Query\Match();
     $elasticaQueryString->setFieldMinimumShouldMatch('content', '80%')->setFieldQuery('content', $query);
     if ($this->useMatchQueryForTitle) {
         $elasticaQueryTitle = new \Elastica\Query\Match();
         $elasticaQueryTitle->setFieldQuery('title', $query)->setFieldMinimumShouldMatch('title', '80%');
     } else {
         $elasticaQueryTitle = new \Elastica\Query\QueryString();
         $elasticaQueryTitle->setDefaultField('title')->setQuery($query);
     }
     $elasticaQueryBool = new \Elastica\Query\BoolQuery();
     $elasticaQueryBool->addShould($elasticaQueryTitle)->addShould($elasticaQueryString)->setMinimumNumberShouldMatch(1);
     $this->applySecurityFilter($elasticaQueryBool);
     if (!is_null($type)) {
         $elasticaQueryType = new \Elastica\Query\Term();
         $elasticaQueryType->setTerm('type', $type);
         $elasticaQueryBool->addMust($elasticaQueryType);
     }
     $rootNode = $this->domainConfiguration->getRootNode();
     if (!is_null($rootNode)) {
         $elasticaQueryRoot = new \Elastica\Query\Term();
         $elasticaQueryRoot->setTerm('root_id', $rootNode->getId());
         $elasticaQueryBool->addMust($elasticaQueryRoot);
     }
     $rescore = new \Elastica\Rescore\Query();
     $rescore->setRescoreQuery($this->getPageBoosts());
     $this->query->setQuery($elasticaQueryBool);
     $this->query->setRescore($rescore);
     $this->query->setHighlight(array('pre_tags' => array('<strong>'), 'post_tags' => array('</strong>'), 'fields' => array('content' => array('fragment_size' => 150, 'number_of_fragments' => 3))));
 }