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);
 }
 /**
  * @expectedException InvalidArgumentException
  */
 public function testSuggestionWithNonNumericContinue()
 {
     $this->paramsParser->parseAndValidate(array('entity' => 'Q1', 'properties' => null, 'continue' => 'drop'));
 }