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; }
/** * @dataProvider provideConstructor */ public function testConstructor($fields) { $term = new TermIndexEntry($fields); $entityId = null; if (isset($fields['entityType']) && isset($fields['entityId'])) { // FIXME: This must be removed once we got rid of all legacy numeric ids. $entityId = LegacyIdInterpreter::newIdFromTypeAndNumber($fields['entityType'], $fields['entityId']); } $this->assertEquals(isset($fields['entityType']) ? $fields['entityType'] : null, $term->getEntityType()); $this->assertEquals($entityId, $term->getEntityId()); $this->assertEquals(isset($fields['termType']) ? $fields['termType'] : null, $term->getType()); $this->assertEquals(isset($fields['termLanguage']) ? $fields['termLanguage'] : null, $term->getLanguage()); $this->assertEquals(isset($fields['termText']) ? $fields['termText'] : null, $term->getText()); $this->assertEquals(isset($fields['termWeight']) ? $fields['termWeight'] : null, $term->getWeight()); }
/** * @param TermIndexEntry $termIndexEntry * * @return TermSearchResult */ private function convertToSearchResult(TermIndexEntry $termIndexEntry) { $entityId = $termIndexEntry->getEntityId(); return new TermSearchResult($termIndexEntry->getTerm(), $termIndexEntry->getType(), $entityId, $this->getLabelDisplayTerm($entityId), $this->getDescriptionDisplayTerm($entityId)); }
/** * @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; }