예제 #1
0
 /**
  *
  * @return string
  */
 public function highlight_thesaurus()
 {
     $value = $this->getValue();
     $databox = $this->databox_field->get_databox();
     $XPATH_thesaurus = $databox->get_xpath_thesaurus();
     $tbranch = $this->databox_field->get_tbranch();
     if (!$tbranch || !$XPATH_thesaurus) {
         return $value;
     }
     // ---------------- new code ----------------------
     $cleanvalue = str_replace(["[[em]]", "[[/em]]", "'"], ["", "", "'"], $value);
     list($term_noacc, $context_noacc) = $this->splitTermAndContext($cleanvalue);
     $term_noacc = $this->app['unicode']->remove_indexer_chars($term_noacc);
     $context_noacc = $this->app['unicode']->remove_indexer_chars($context_noacc);
     // find all synonyms in all related branches
     $q = "(" . $tbranch . ")//sy[@w='" . $term_noacc . "'";
     if ($context_noacc) {
         $q .= " and @k='" . $context_noacc . "']";
     } else {
         $q .= " and not(@k)]";
     }
     $q .= "/../sy";
     $nodes = $XPATH_thesaurus->query($q);
     // loop on every sy found
     $bestnode = null;
     $bestnote = 0;
     foreach ($nodes as $node) {
         $note = 0;
         $note += $node->getAttribute("lng") == $this->app['locale'] ? 4 : 0;
         $note += $node->getAttribute("w") == $term_noacc ? 2 : 0;
         if ($context_noacc != "") {
             $note += $node->getAttribute("k") == $context_noacc ? 1 : 0;
         }
         if ($note > $bestnote) {
             $bestnode = $node;
         }
     }
     if ($bestnode) {
         list($term, $context) = $this->splitTermAndContext(str_replace(["[[em]]", "[[/em]]"], ["", ""], $value));
         // a value has been found in thesaurus, update value & set the query to bounce to the value
         $this->value = $bestnode->getAttribute('v');
         $this->qjs = $term . ($context ? '[' . $context . ']' : '');
         $this->isThesaurusValue = true;
     } else {
         $this->isThesaurusValue = false;
     }
     return $this;
 }
예제 #2
0
 public function testGet_tbranch()
 {
     $this->assertEquals('', $this->object_mono->get_tbranch());
     $this->assertEquals('', $this->object_multi->get_tbranch());
 }
예제 #3
0
파일: V1.php 프로젝트: nlegoff/Phraseanet
 /**
  * Retrieve informations about one \databox metadata field
  *
  * @param  \databox_field $databox_field
  *
  * @return array
  */
 private function list_databox_metadata_field_properties(\databox_field $databox_field)
 {
     return ['id' => $databox_field->get_id(), 'namespace' => $databox_field->get_tag()->getGroupName(), 'source' => $databox_field->get_tag()->getTagname(), 'tagname' => $databox_field->get_tag()->getName(), 'name' => $databox_field->get_name(), 'labels' => ['fr' => $databox_field->get_label('fr'), 'en' => $databox_field->get_label('en'), 'de' => $databox_field->get_label('de'), 'nl' => $databox_field->get_label('nl')], 'separator' => $databox_field->get_separator(), 'thesaurus_branch' => $databox_field->get_tbranch(), 'type' => $databox_field->get_type(), 'indexable' => $databox_field->is_indexable(), 'multivalue' => $databox_field->is_multi(), 'readonly' => $databox_field->is_readonly(), 'required' => $databox_field->is_required()];
 }