Ejemplo n.º 1
0
 /**
  * @see ApiBase::execute()
  */
 public function execute()
 {
     $extracted = $this->extractRequestParams();
     $params = $this->paramsParser->parseAndValidate($extracted);
     $suggestionGenerator = new SuggestionGenerator($this->entityLookup, $this->termIndex, $this->suggester);
     if ($params->entity !== null) {
         $suggestions = $suggestionGenerator->generateSuggestionsByItem($params->entity, $params->suggesterLimit, $params->minProbability, $params->context);
     } else {
         $suggestions = $suggestionGenerator->generateSuggestionsByPropertyList($params->properties, $params->suggesterLimit, $params->minProbability, $params->context);
     }
     $suggestions = $suggestionGenerator->filterSuggestions($suggestions, $params->search, $params->language, $params->resultSize);
     // Build result array
     $resultBuilder = new ResultBuilder($this->getResult(), $this->termIndex, $this->entityTitleLookup, $params->search);
     $entries = $resultBuilder->createResultArray($suggestions, $params->language, $params->search);
     // merge with search result if possible and necessary
     if (count($entries) < $params->resultSize && $params->search !== '') {
         $searchResult = $this->querySearchApi($params->resultSize, $params->search, $params->language);
         $entries = $resultBuilder->mergeWithTraditionalSearchResults($entries, $searchResult, $params->resultSize);
     }
     // Define Result
     $slicedEntries = array_slice($entries, $params->continue, $params->limit);
     ApiResult::setIndexedTagName($slicedEntries, 'search');
     $this->getResult()->addValue(null, 'search', $slicedEntries);
     $this->getResult()->addValue(null, 'success', 1);
     if (count($entries) >= $params->resultSize) {
         $this->getResult()->addValue(null, 'search-continue', $params->resultSize);
     }
     $this->getResult()->addValue('searchinfo', 'search', $params->search);
 }
 public function testMergeWithTraditionalSearchResults()
 {
     $suggesterResult = array(array('id' => '8'), array('id' => '14'), array('id' => '20'));
     $searchResult = array(array('id' => '7'), array('id' => '8'), array('id' => '13'), array('id' => '14'), array('id' => '15'), array('id' => '16'));
     $mergedResult = $this->resultBuilder->mergeWithTraditionalSearchResults($suggesterResult, $searchResult, 5);
     $expected = array(array('id' => '8'), array('id' => '14'), array('id' => '20'), array('id' => '7'), array('id' => '13'));
     $this->assertEquals($mergedResult, $expected);
 }