Example #1
0
 /**
  * Delete and rebuild the entire search index
  *
  * @param SearchHandlerInterface $searchHandler
  * @return \Illuminate\Http\JsonResponse
  */
 public function reindex(SearchHandlerInterface $searchHandler)
 {
     //TODO: Add ACL
     try {
         $searchHandler->reindex();
     } catch (\Exception $e) {
         return \Response::json($e->getMessage());
     }
     return \Response::json('Reindex successful');
 }
Example #2
0
 /**
  * Find items that relate to the tags passed in
  *
  * @param Request $request
  * @param SearchHandlerInterface $searchHandler
  * @return \Illuminate\View\View
  */
 public function findItemsForTags(Request $request, SearchHandlerInterface $searchHandler)
 {
     $q = $request->input('q');
     $filters['must'] = ['tags' => $q];
     $items = $searchHandler->filteredSearch($filters, Auth::user(), 'created_at', 'desc');
     $title = "Tag : " . $q;
     return view('all', ['items' => $items, 'title' => $title]);
 }
 /**
  * Execute the console command.
  *
  * @param ImageHandlerInterface $imageHandler
  * @param CacheHandlerInterface $cacheHandler
  * @param SearchHandlerInterface $searchHandler
  * @return mixed
  */
 public function handle(ImageHandlerInterface $imageHandler, CacheHandlerInterface $cacheHandler, SearchHandlerInterface $searchHandler)
 {
     // Find all links with photos URLs that need thumbnails
     $links = Link::with('item', 'item.user')->whereNull('photo')->take(100)->get();
     /* @var $link \App\Models\Link */
     foreach ($links as $link) {
         // Try to generate a thumbnail for the desired photo
         try {
             $generatedFilename = $imageHandler->generateThumbnail($link->photo_url);
             if ($generatedFilename) {
                 $link->photo = $generatedFilename;
                 $link->save();
                 // Update Search
                 $searchHandler->update($link);
                 // Update cache for user
                 $cacheHandler->del(CacheHandlerInterface::MAINPAGE, $link->item->user->id);
             }
         } catch (\Exception $e) {
             error_log($e);
         }
     }
 }
Example #4
0
 /**
  * Update an item
  *
  * @param $inputs
  * @return bool
  */
 public function update($inputs)
 {
     /* @var $item Item */
     $item = $this->itemsRepo->get($inputs['itemId']);
     $item->value = $inputs['value'];
     $item->description = $inputs['description'];
     $subclass = get_class($item->itemable);
     if ($subclass == 'App\\Models\\Link') {
         $item->itemable->title = $inputs['value'];
     }
     // Tags
     $this->tagsRepo->updateForItem($item, $inputs, Auth::user());
     // Cache
     $this->cacheHandler->del(CacheHandlerInterface::MAINPAGE);
     $this->cacheHandler->del(CacheHandlerInterface::TAGS);
     // Save
     $item->save();
     // Update Search
     $this->searchHandler->update($item->itemable);
     return $item;
 }
 /**
  * Generate the cache item for a specific Tag with the given Links
  *
  * @param $tag
  * @param CacheHandlerInterface $cacheHandler
  * @param SearchHandlerInterface $searchHandler
  * @internal param $links
  */
 private function generate($tag, CacheHandlerInterface $cacheHandler, SearchHandlerInterface $searchHandler)
 {
     // Find items for the requested Tag
     $filters['must'] = ['tags' => $tag->name];
     $filters['should'] = ['discovery_setting' => 'attributed'];
     $filters['should'] = ['discovery_setting' => 'anonymous'];
     $links = $searchHandler->filteredSearch($filters, null, 'created_at', 'desc', 10);
     $cacheHandler->set(CacheHandlerInterface::DISCOVER_TAG, $links, $tag->name);
 }