public function getTermKey(TermIndexEntry $term)
 {
     $key = '';
     if ($term->getEntityId() !== null) {
         $key .= $term->getEntityId()->getSerialization();
     }
     $key .= '/';
     if ($term->getType() !== null) {
         $key .= $term->getType();
     }
     $key .= '.';
     if ($term->getLanguage() !== null) {
         $key .= $term->getLanguage();
     }
     $key .= ':';
     if ($term->getText() !== null) {
         $key .= $term->getText();
     }
     return $key;
 }
 public function testClone()
 {
     $term = new TermIndexEntry(array('termText' => 'Foo'));
     $clone = clone $term;
     $clone->setText('Bar');
     $this->assertEquals('Bar', $clone->getText(), "clone must change when modified");
     // sanity
     $this->assertEquals('Foo', $term->getText(), "original must stay the same when clone is modified");
     $clone = clone $term;
     $this->assertEquals($term, $clone, "clone must be equal to original");
 }
 /**
  * @param array $entry
  * @param TermIndexEntry $term
  */
 private function checkAndSetAlias(array &$entry, TermIndexEntry $term)
 {
     // Do not add more than one matching alias to the "aliases" field.
     if (!empty($entry['aliases'])) {
         return;
     }
     if (preg_match($this->searchPattern, $term->getText())) {
         if (!isset($entry['aliases'])) {
             $entry['aliases'] = array();
             ApiResult::setIndexedTagName($entry['aliases'], 'alias');
         }
         $entry['aliases'][] = $term->getText();
     }
 }
 /**
  * @param TermIndexEntry $term
  * @param TermIndexEntry[] $templates
  * @param array $options
  *
  * @return bool
  */
 private function termMatchesTemplates(TermIndexEntry $term, array $templates, array $options = array())
 {
     foreach ($templates as $template) {
         if ($template->getType() !== null && $template->getType() != $term->getType()) {
             continue;
         }
         if ($template->getEntityType() !== null && $template->getEntityType() != $term->getEntityType()) {
             continue;
         }
         if ($template->getLanguage() !== null && $template->getLanguage() != $term->getLanguage()) {
             continue;
         }
         if ($template->getText() !== null && !$this->textMatches($template->getText(), $term->getText(), $options)) {
             continue;
         }
         if ($template->getEntityId() !== null && !$template->getEntityId()->equals($term->getEntityType())) {
             continue;
         }
         return true;
     }
     return false;
 }