Exemplo n.º 1
0
 /**
  * Build search results
  * @return array[AbstractSearchResult]
  */
 public function getResult()
 {
     // relevant search by string query
     $records = Content::where('display', '=', 1)->search($this->query)->take($this->limit)->get();
     // check if result is not empty
     if ($records->count() < 1) {
         return [];
     }
     // build result items
     $result = [];
     foreach ($records as $item) {
         /** @var \Apps\ActiveRecord\Content $item */
         $title = $item->getLocaled('title');
         $text = App::$Security->strip_tags($item->getLocaled('text'));
         $snippet = Text::snippet($text);
         // prevent empty items
         if (Str::likeEmpty($title)) {
             continue;
         }
         // initialize abstract response pattern
         $res = new AbstractSearchResult();
         $res->setTitle($title);
         $res->setSnippet($snippet);
         $res->setDate($item->created_at);
         $res->setRelevance((int) $item->relevance);
         $res->setUri('/content/read/' . $item->getPath());
         // accumulate response var
         $result[] = $res;
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Build search results. Should return array collection: [AbstractSearchResult]
  * @return array
  */
 public function getResult()
 {
     // search in comments post
     $query = CommentPost::where('moderate', '=', 0)->search($this->query)->take($this->limit)->get();
     // check if response is empty
     if ($query->count() < 1) {
         return [];
     }
     // build output
     $result = [];
     foreach ($query as $item) {
         /** @var CommentPost $item */
         $snippet = App::$Security->strip_tags($item->message);
         $snippet = Text::snippet($snippet);
         // make unique instance object
         $instance = new AbstractSearchResult();
         $instance->setTitle(App::$Translate->get('Search', 'Comment on the page'));
         $instance->setSnippet($snippet);
         $instance->setUri($item->pathway . '#comments-list');
         $instance->setDate($item->created_at);
         $instance->setRelevance((int) $item->relevance);
         // add instance to result set
         $result[] = $instance;
     }
     return $result;
 }