public function testExcerptFromSimpleQuery()
 {
     $record = self::$DI['record_2'];
     $query_string = 'boomboklot' . $record->get_record_id() . 'excerptSimpleQuery';
     $this->editRecord($query_string, $record);
     self::$searchEngine->addRecord($record);
     $this->updateIndex();
     self::$searchEngine->resetCache();
     $results = self::$searchEngine->query($query_string, 0, 1, $this->options);
     $fields = [];
     $foundRecord = $results->getResults()->first();
     $this->assertInstanceOf('\\record_adapter', $foundRecord);
     foreach ($foundRecord->get_caption()->get_fields() as $field) {
         foreach ($field->get_values() as $metaId => $v) {
             $values[$metaId] = ['value' => $v->getValue(), 'from_thesaurus' => false, 'qjs' => null];
         }
         $fields[$field->get_name()] = ['values' => $values, 'separator' => ';'];
     }
     $found = false;
     $highlightedValues = self::$searchEngine->excerpt($query_string, $fields, $foundRecord);
     foreach ($highlightedValues as $fieldValues) {
         foreach ($fieldValues as $metaId => $field) {
             if (strpos($field, '[[em]]') !== false && strpos($field, '[[/em]]') !== false) {
                 $found = true;
                 break 2;
             }
         }
     }
     if (!$found && count($highlightedValues) > 0) {
         $this->fail('Unable to build the excerpt');
     }
 }
Exemplo n.º 2
0
 /**
  * @todo move this fun in caption_field object
  * @param  string                $highlight
  * @param  array                 $grep_fields
  * @param  SearchEngineInterface $searchEngine
  * @return array
  */
 protected function highlight_fields($highlight, array $grep_fields = null, SearchEngineInterface $searchEngine = null, $includeBusiness = false, SearchEngineOptions $options = null)
 {
     $fields = [];
     foreach ($this->get_fields($grep_fields, $includeBusiness) as $meta_struct_id => $field) {
         $value = preg_replace("(([^']{1})((https?|file):((/{2,4})|(\\{2,4}))[\\w:#%/;\$()~_?/\\-=\\\\.&]*)([^']{1}))", '$1 $2 <a title="' . $this->app->trans('Open the URL in a new window') . '" class="ui-icon ui-icon-extlink" href="$2" style="display:inline;padding:2px 5px;margin:0 4px 0 2px;" target="_blank"> &nbsp;</a>$7', $highlight ? $field->highlight_thesaurus() : $field->get_serialized_values(false, false));
         $fields[$field->get_name()] = ['value' => $value, 'label' => $field->get_databox_field()->get_label($this->app['locale']), 'separator' => $field->get_databox_field()->get_separator()];
     }
     if ($searchEngine instanceof SearchEngineInterface) {
         $ret = $searchEngine->excerpt($highlight, $fields, $this->record, $options);
         if ($ret) {
             $n = -1;
             foreach ($fields as $key => $value) {
                 $n++;
                 if (!isset($fields[$key])) {
                     continue;
                 }
                 if (strpos($fields[$key]['value'], '<a class="bounce" ') !== false) {
                     continue;
                 }
                 //if(strpos($fields[$key]['value'], '<a ') === false)
                 $fields[$key]['value'] = $ret[$n];
             }
         }
     }
     return $fields;
 }
Exemplo n.º 3
0
 /**
  *
  * @param string                $highlight
  * @param array                 $grep_fields
  * @param SearchEngineInterface $searchEngine
  * @param Boolean               $includeBusiness
  *
  * @return array
  */
 public function get_highlight_fields($highlight = '', array $grep_fields = null, SearchEngineInterface $searchEngine = null, $includeBusiness = false, SearchEngineOptions $options = null)
 {
     $fields = [];
     foreach ($this->get_fields($grep_fields, $includeBusiness) as $meta_struct_id => $field) {
         $values = [];
         foreach ($field->get_values() as $metaId => $v) {
             $values[$metaId] = ['value' => $v->getValue(), 'from_thesaurus' => $highlight ? $v->isThesaurusValue() : false, 'qjs' => $v->getQjs()];
         }
         $fields[$field->get_name()] = ['values' => $values, 'name' => $field->get_name(), 'label_name' => $field->get_databox_field()->get_label($this->app['locale']), 'separator' => $field->get_databox_field()->get_separator(), 'sbas_id' => $field->get_databox_field()->get_databox()->get_sbas_id()];
     }
     if ($searchEngine instanceof SearchEngineInterface) {
         $ret = $searchEngine->excerpt($highlight, $fields, $this->record, $options);
         // sets highlighted value from search engine, highlighted values will now
         // be surrounded by [[em]][[/em]] tags
         if ($ret) {
             foreach ($fields as $key => $value) {
                 if (!isset($ret[$key])) {
                     continue;
                 }
                 foreach ($ret[$key] as $metaId => $newValue) {
                     $fields[$key]['values'][$metaId]['value'] = $newValue;
                 }
             }
         }
     }
     return $fields;
 }