コード例 #1
0
 /**
  * @param Suggestion[] $suggestions
  * @param string $language
  * @return array[]
  */
 public function createResultArray(array $suggestions, $language)
 {
     $entries = array();
     $ids = array();
     foreach ($suggestions as $suggestion) {
         $id = $suggestion->getPropertyId();
         $ids[] = $id;
     }
     //See SearchEntities
     $terms = $this->termIndex->getTermsOfEntities($ids, null, array($language));
     $clusteredTerms = $this->clusterTerms($terms);
     foreach ($suggestions as $suggestion) {
         $id = $suggestion->getPropertyId();
         $entries[] = $this->buildEntry($id, $clusteredTerms, $suggestion);
     }
     return $entries;
 }
コード例 #2
0
 /**
  * @param EntityId[] $entityIds
  * @param string[]|null $termTypes
  * @param string[]|null $languageCodes
  *
  * @return TermIndexEntry[]
  */
 private function getTermsOfEntities(array $entityIds, array $termTypes = null, array $languageCodes = null)
 {
     $entityIdGroups = $this->splitPageEntityMapByType($entityIds);
     $terms = array();
     foreach ($entityIdGroups as $entityIds) {
         $terms = array_merge($terms, $this->termIndex->getTermsOfEntities($entityIds, $termTypes, $languageCodes));
     }
     return $terms;
 }
コード例 #3
0
 /**
  * Loads a set of terms into the buffer.
  * The source from which to fetch would typically be supplied to the buffer's constructor.
  *
  * @param EntityId[] $entityIds
  * @param string[]|null $termTypes
  * @param string[]|null $languageCodes
  *
  * @throws StorageException
  */
 public function prefetchTerms(array $entityIds, array $termTypes = null, array $languageCodes = null)
 {
     if (empty($entityIds)) {
         return;
     }
     // We could first check what's already in the buffer, but it's hard to determine which
     // entities are actually "fully covered" by the cached terms. Also, our current use case
     // (the ChangesListInitRows hook) would generally, trigger only one call to prefetchTerms,
     // before any call to getTermsOfType().
     $entityIdsByType = $this->groupEntityIds($entityIds);
     $terms = array();
     foreach ($entityIdsByType as $entityIdGroup) {
         $terms = array_merge($terms, $this->termIndex->getTermsOfEntities($entityIdGroup, $termTypes, $languageCodes));
     }
     $bufferedKeys = $this->setBufferedTermObjects($terms);
     if (!empty($languageCodes)) {
         $this->setUndefinedTerms($entityIds, $termTypes, $languageCodes, $bufferedKeys);
     }
 }