Example #1
0
 /**
  * @return Form
  */
 protected function createComponentSearchForm()
 {
     $form = new Form();
     $form->setTranslator($this->translator);
     $form->addProtection();
     $defaultSearchValue = $this->search ? $this->search->getInput() : NULL;
     $form->addText('search')->setRequired()->setValue($defaultSearchValue);
     $form->addSubmit('submit');
     $form->onSuccess[] = function (Form $form) {
         $this->onSavedSearch($form->getValues()->search);
     };
     return $form;
 }
Example #2
0
 /**
  * @param Search $search
  * @return Result[]
  */
 public function search(Search $search)
 {
     $bool = new Bool();
     $match = new Match();
     $match->setField('text', $search->getInput());
     $bool->addMust($match);
     $query = new Query();
     $query->setQuery($bool);
     $query->setHighlight(['pre_tags' => ['<mark>'], 'post_tags' => ['</mark>'], 'fields' => ['text' => ['highlight_query' => [$bool->toArray()]]]]);
     $results = $this->getIndex()->search($query, 50)->getResults();
     $this->onSearch($search, $results);
     return $results;
 }
 /**
  * @param Search $search
  * @param array $results
  */
 public function onSearch(Search $search, array $results)
 {
     $resultsCount = count($results);
     $message = "Searching '{$search->getInput()}' #{$search->getId()} with {$resultsCount} results.";
     $this->loggerChannel->addDebug($message);
 }