예제 #1
0
 public function searchRelatedEpisodes(Episode $episode, $numberResults = 5)
 {
     $tagtext = implode(" ", $episode->getTags()->toArray());
     $boolQuery = new \Elastica\Query\BoolQuery();
     $multiquery = new \Elastica\Query\MultiMatch();
     $multiquery->setFields(['name', 'description', 'series']);
     $multiquery->setQuery($tagtext);
     $multiquery->setType(\Elastica\Query\MultiMatch::TYPE_MOST_FIELDS);
     $boolQuery->addMust($multiquery);
     $activeQuery = new \Elastica\Query\Term();
     $activeQuery->setTerm('is_active', true);
     $boolQuery->addMust($activeQuery);
     $excludeEpisodeQuery = new \Elastica\Query\Term();
     $excludeEpisodeQuery->setTerm('id', $episode->getId());
     $boolQuery->addMustNot($excludeEpisodeQuery);
     return $this->episodeFinder->find($boolQuery, $numberResults);
 }
 /**
  * Builds a multi match query with the cross_field type.
  *
  * @param array $boostedField of boosted fields
  * @param string $queryString the query
  * @param string $minShouldMatch the MinimumShouldMatch value
  * @return \Elastica\Query\MultiMatch
  */
 private function buildCrossFields(array $boostedFields, $queryString, $minShouldMatch)
 {
     $fields = array();
     foreach ($boostedFields as $f) {
         $fields[] = $f['field'] . '^' . $f['boost'];
     }
     $cross = new \Elastica\Query\MultiMatch();
     $cross->setQuery($queryString);
     $cross->setFields($fields);
     $cross->setType('cross_fields');
     $cross->setMinimumShouldMatch($minShouldMatch);
     return $cross;
 }