/** * @param SearchCriteria $criteria * @param int|null $limit * @param int $offset * @param array $load An array of relationships to load on the results. * @return SearchResults */ public function search(SearchCriteria $criteria, $limit = null, $offset = 0, array $load = []) { $actor = $criteria->actor; $query = $this->discussions->query()->whereVisibleTo($actor); // Construct an object which represents this search for discussions. // Apply gambits to it, sort, and paging criteria. Also give extensions // an opportunity to modify it. $search = new DiscussionSearch($query->getQuery(), $actor); $this->gambits->apply($search, $criteria->query); $this->applySort($search, $criteria->sort); $this->applyOffset($search, $offset); $this->applyLimit($search, $limit + 1); // TODO: inject dispatcher event(new ConfigureDiscussionSearch($search, $criteria)); // Execute the search query and retrieve the results. We get one more // results than the user asked for, so that we can say if there are more // results. If there are, we will get rid of that extra result. $discussions = $query->get(); $areMoreResults = $limit > 0 && $discussions->count() > $limit; if ($areMoreResults) { $discussions->pop(); } // The relevant posts relationship isn't a typical Eloquent // relationship; rather, we need to extract that information from our // search object. We will delegate that task and prevent Eloquent // from trying to load it. if (in_array('relevantPosts', $load)) { $this->loadRelevantPosts($discussions, $search); $load = array_diff($load, ['relevantPosts', 'relevantPosts.discussion', 'relevantPosts.user']); } Discussion::setStateUser($actor); $discussions->load($load); return new SearchResults($discussions, $areMoreResults); }
public function registerGambits() { $this->app->when('Flarum\\Core\\Users\\Search\\UserSearcher')->needs('Flarum\\Core\\Search\\GambitManager')->give(function (Container $app) { $gambits = new GambitManager($app); $gambits->setFulltextGambit('Flarum\\Core\\Users\\Search\\Gambits\\FulltextGambit'); event(new RegisterUserGambits($gambits)); return $gambits; }); }
/** * Register the service provider. * * @return void */ public function register() { $this->app->bind('Flarum\\Core\\Discussions\\Search\\Fulltext\\Driver', 'Flarum\\Core\\Discussions\\Search\\Fulltext\\MySqlFulltextLikeModeDriver'); $this->app->when('Flarum\\Core\\Discussions\\Search\\DiscussionSearcher')->needs('Flarum\\Core\\Search\\GambitManager')->give(function (Container $app) { $gambits = new GambitManager($app); $gambits->setFulltextGambit('Flarum\\Core\\Discussions\\Search\\Gambits\\FulltextGambit'); $gambits->add('Flarum\\Core\\Discussions\\Search\\Gambits\\AuthorGambit'); $gambits->add('Flarum\\Core\\Discussions\\Search\\Gambits\\UnreadGambit'); event(new RegisterDiscussionGambits($gambits)); return $gambits; }); }
public function registerGambits() { $this->app->when('Flarum\\Core\\Search\\Discussions\\DiscussionSearcher')->needs('Flarum\\Core\\Search\\GambitManager')->give(function () { $gambits = new GambitManager($this->app); $gambits->add('Flarum\\Core\\Search\\Discussions\\Gambits\\AuthorGambit'); $gambits->add('Flarum\\Core\\Search\\Discussions\\Gambits\\UnreadGambit'); $gambits->setFulltextGambit('Flarum\\Core\\Search\\Discussions\\Gambits\\FulltextGambit'); event(new RegisterDiscussionGambits($gambits)); return $gambits; }); $this->app->when('Flarum\\Core\\Search\\Users\\UserSearcher')->needs('Flarum\\Core\\Search\\GambitManager')->give(function () { $gambits = new GambitManager($this->app); $gambits->setFulltextGambit('Flarum\\Core\\Search\\Users\\Gambits\\FulltextGambit'); event(new RegisterUserGambits($gambits)); return $gambits; }); }
/** * @param SearchCriteria $criteria * @param int|null $limit * @param int $offset * * @return SearchResults */ public function search(SearchCriteria $criteria, $limit = null, $offset = 0) { $actor = $criteria->actor; $query = $this->pages->query(); if ($actor !== null && !$actor->isAdmin()) { $query->whereIsHidden(0); } $search = new PageSearch($query->getQuery(), $actor); $this->gambits->apply($search, $criteria->query); $this->applySort($search, $criteria->sort); $this->applyOffset($search, $offset); $this->applyLimit($search, $limit + 1); $pages = $query->get(); if ($areMoreResults = $limit > 0 && $pages->count() > $limit) { $pages->pop(); } return new SearchResults($pages, $areMoreResults); }
/** * @param SearchCriteria $criteria * @param int|null $limit * @param int $offset * @param array $load An array of relationships to load on the results. * @return SearchResults */ public function search(SearchCriteria $criteria, $limit = null, $offset = 0, array $load = []) { $actor = $criteria->actor; $query = $this->users->query()->whereVisibleTo($actor); // Construct an object which represents this search for users. // Apply gambits to it, sort, and paging criteria. Also give extensions // an opportunity to modify it. $search = new UserSearch($query->getQuery(), $actor); $this->gambits->apply($search, $criteria->query); $this->applySort($search, $criteria->sort); $this->applyOffset($search, $offset); $this->applyLimit($search, $limit + 1); event(new UserSearchWillBePerformed($search, $criteria)); // Execute the search query and retrieve the results. We get one more // results than the user asked for, so that we can say if there are more // results. If there are, we will get rid of that extra result. $users = $query->get(); if ($areMoreResults = $limit > 0 && $users->count() > $limit) { $users->pop(); } $users->load($load); return new SearchResults($users, $areMoreResults); }
public function registerDiscussionGambits() { $this->app->when('Flarum\\Core\\Search\\Discussion\\DiscussionSearcher')->needs('Flarum\\Core\\Search\\GambitManager')->give(function (Container $app) { $gambits = new GambitManager($app); $gambits->setFulltextGambit('Flarum\\Core\\Search\\Discussion\\Gambit\\FulltextGambit'); $gambits->add('Flarum\\Core\\Search\\Discussion\\Gambit\\AuthorGambit'); $gambits->add('Flarum\\Core\\Search\\Discussion\\Gambit\\CreatedGambit'); $gambits->add('Flarum\\Core\\Search\\Discussion\\Gambit\\HiddenGambit'); $gambits->add('Flarum\\Core\\Search\\Discussion\\Gambit\\UnreadGambit'); $app->make('events')->fire(new ConfigureDiscussionGambits($gambits)); return $gambits; }); }
/** * @param string $gambit */ public function register($gambit) { $this->gambits->add($gambit); }