/**
  * @param Escaper $escaper
  * @param SearchContext $context
  * @param string $value
  * @param bool $updateHighlightSourceRef
  * @param callable $fieldF
  * @return callable
  */
 private static function insourceOrIntitle($escaper, $context, $value, $updateHighlightSourceRef, $fieldF)
 {
     list($queryString, $fuzzyQuery) = $escaper->fixupWholeQueryString($escaper->fixupQueryStringPart($value));
     $field = $fieldF($queryString);
     $query = new \Elastica\Query\QueryString($queryString);
     $query->setFields(array($field));
     $query->setDefaultOperator('AND');
     $query->setAllowLeadingWildcard($escaper->getAllowLeadingWildcard());
     $query->setFuzzyPrefixLength(2);
     $query->setRewrite('top_terms_boost_1024');
     $wrappedQuery = $context->wrapInSaferIfPossible($query, false);
     $updateReferences = function (&$fuzzyQueryRef, &$filterDestinationRef, &$highlightSourceRef, &$searchContainedSyntaxRef) use($fuzzyQuery, $wrappedQuery, $updateHighlightSourceRef) {
         $fuzzyQueryRef = $fuzzyQuery;
         $filterDestinationRef[] = new \Elastica\Filter\Query($wrappedQuery);
         if ($updateHighlightSourceRef) {
             $highlightSourceRef[] = array('query' => $wrappedQuery);
         }
         $searchContainedSyntaxRef = true;
     };
     return $updateReferences;
 }
 /**
  * @dataProvider provideRescoreProfilesWithWindowSize
  */
 public function testWindowSizeOverride($settings, $expected)
 {
     $config = new HashSearchConfig($settings);
     $context = new SearchContext($config, null);
     $context->setBoostLinks(true);
     $builder = new RescoreBuilder($context, $config->getElement('CirrusSearchRescoreProfiles', 'default'));
     $rescore = $builder->build();
     $this->assertEquals($expected, $rescore[0]['window_size']);
 }
 /**
  * @todo: refactor as we may want to implement many different way to build
  *        the main query.
  * @param string[] $fields
  * @param string $queryString
  * @param int $phraseSlop
  * @param boolean $isRescore
  * @return \Elastica\Query\Simple
  */
 private function buildSearchTextQueryForFields(array $fields, $queryString, $phraseSlop, $isRescore, $forHighlight = false)
 {
     $searchTextQueryBuilder = $this->searchContext->searchTextQueryBuilder($queryString);
     if ($isRescore) {
         return $searchTextQueryBuilder->buildRescoreQuery($fields, $queryString, $phraseSlop);
     } else {
         if ($forHighlight) {
             return $searchTextQueryBuilder->buildHighlightQuery($fields, $queryString, $phraseSlop);
         } else {
             return $searchTextQueryBuilder->buildMainQuery($fields, $queryString, $phraseSlop);
         }
     }
 }
 /**
  * Builds a new function score chain.
  * @param SearchContext $context
  * @param string $chainName the name of the chain (must be a valid
  * chain in wgCirrusSearchRescoreFunctionScoreChains)
  */
 public function __construct(SearchContext $context, $chainName)
 {
     $this->chainName = $chainName;
     $this->context = $context;
     $this->functionScore = new FunctionScoreDecorator();
     $this->chain = $context->getConfig()->getElement('CirrusSearchRescoreFunctionScoreChains', $chainName);
     if ($this->chain === null) {
         throw new InvalidRescoreProfileException("Unknown rescore function chain {$chainName}");
     }
     $params = array_intersect_key($this->chain, array_flip(self::$functionScoreParams));
     foreach ($params as $param => $value) {
         $this->functionScore->setParam($param, $value);
     }
 }