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');
     }
 }
Пример #2
0
 public function get_train($pos = 0, $query = '', SearchEngineInterface $search_engine = null)
 {
     if ($this->train) {
         return $this->train;
     }
     switch ($this->env) {
         case 'RESULT':
             $perPage = 56;
             $index = $pos - 3 < 0 ? 0 : $pos - 3;
             $results = $search_engine->query($query, $index, $perPage);
             $this->train = $results->getResults()->toArray();
             break;
         case 'BASK':
             $this->train = $this->container->getElements();
             break;
         case 'REG':
             $this->train = $this->container->get_children();
             break;
     }
     return $this->train;
 }
Пример #3
0
 public function __construct(Application $app, $env, $pos, $contId, SearchEngineInterface $search_engine = null, $query = '', SearchEngineOptions $options = null)
 {
     $number = null;
     $this->env = $env;
     $this->app = $app;
     $this->pos = $pos;
     $this->searchEngine = $search_engine;
     $this->query = $query;
     $this->options = $options;
     switch ($env) {
         case "RESULT":
             if (null === $search_engine) {
                 throw new \LogicException('Search Engine should be provided');
             }
             $results = $search_engine->query($query, (int) $pos, 1, $options);
             if ($results->getResults()->isEmpty()) {
                 throw new Exception('Record introuvable');
             }
             foreach ($results->getResults() as $record) {
                 $number = $pos;
                 $this->original_item = $record;
                 $sbas_id = $record->getDataboxId();
                 $record_id = $record->getRecordId();
                 break;
             }
             break;
         case "REG":
             $contId = explode('_', $contId);
             $sbas_id = $contId[0];
             $record_id = $contId[1];
             $this->container = new record_adapter($app, $sbas_id, $record_id);
             $this->original_item = $this->container;
             if ($pos == 0) {
                 $number = 0;
             } else {
                 $children = $this->container->get_children();
                 foreach ($children as $child) {
                     $sbas_id = $child->get_sbas_id();
                     $this->original_item = $child;
                     $record_id = $child->get_record_id();
                     if ($child->getNumber() == $pos) {
                         break;
                     }
                 }
                 $number = $pos;
                 $this->total = $children->get_count();
             }
             break;
         case "BASK":
             $Basket = $app['converter.basket']->convert($contId);
             $app['acl.basket']->hasAccess($Basket, $app->getAuthenticatedUser());
             /* @var $Basket Basket */
             $this->container = $Basket;
             $this->total = $Basket->getElements()->count();
             $i = 0;
             $first = true;
             foreach ($Basket->getElements() as $element) {
                 /* @var $element BasketElement */
                 $i++;
                 if ($first) {
                     $this->original_item = $element;
                     $sbas_id = $element->getRecord($this->app)->get_sbas_id();
                     $record_id = $element->getRecord($this->app)->get_record_id();
                     $this->name = $Basket->getName();
                     $number = $element->getOrd();
                 }
                 $first = false;
                 if ($element->getOrd() == $pos) {
                     $this->original_item = $element;
                     $sbas_id = $element->getRecord($this->app)->get_sbas_id();
                     $record_id = $element->getRecord($this->app)->get_record_id();
                     $this->name = $Basket->getName();
                     $number = $element->getOrd();
                 }
             }
             break;
         case "FEED":
             $entry = $app['repo.feed-entries']->find($contId);
             $this->container = $entry;
             $this->total = count($entry->getItems());
             $i = 0;
             $first = true;
             foreach ($entry->getItems() as $element) {
                 $i++;
                 if ($first) {
                     $sbas_id = $element->getRecord($this->app)->get_sbas_id();
                     $record_id = $element->getRecord($this->app)->get_record_id();
                     $this->name = $entry->getTitle();
                     $this->original_item = $element;
                     $number = $element->getOrd();
                 }
                 $first = false;
                 if ($element->getOrd() == $pos) {
                     $sbas_id = $element->getRecord($this->app)->get_sbas_id();
                     $record_id = $element->getRecord($this->app)->get_record_id();
                     $this->name = $entry->getTitle();
                     $this->original_item = $element;
                     $number = $element->getOrd();
                 }
             }
             break;
     }
     parent::__construct($app, $sbas_id, $record_id, $number);
 }