示例#1
0
 public function buildIndex()
 {
     $links = Links::get();
     $keywords = Keywords::get();
     $titles = Titles::get();
     foreach ($links as $link) {
         SearchIndex::upsertToIndex($link);
     }
     foreach ($keywords as $keyword) {
         SearchIndex::upsertToIndex($keyword);
     }
     foreach ($titles as $title) {
         SearchIndex::upsertToIndex($title);
     }
     return 'indexed all links and keywords';
 }
示例#2
0
 /**
  * Persist keywords
  * @param  Links $link
  * @param  array $keywords
  * @property string $new_keyword->id Id of the keyword
  * @return void           
  */
 public function attachKeywords($link, $keywords)
 {
     $existing_keywords = array_pluck($link->keywords->toArray(), 'id');
     foreach ($keywords as $keyword) {
         $keyword_object = Keywords::make($keyword['text'], str_slug($keyword['text']));
         $new_keyword = $this->keywords->save($keyword_object);
         SearchIndex::upsertToIndex($new_keyword);
         if (!in_array($new_keyword->id, $existing_keywords)) {
             $link->keywords()->attach($new_keyword->id, ['relevance' => $keyword['relevance']]);
         }
     }
 }
示例#3
0
 public function getBySlug($slug)
 {
     return Keywords::whereSlug($slug)->first();
 }