searcher = $searcherClass; } /** * Add a gambit to this searcher. Gambits are used to filter search queries. * * @param string $gambitClass: The ::class attribute of the gambit you are adding. * This gambit must extend \Flarum\Search\AbstractRegexGambit * @return self */ public function addGambit(string $gambitClass): self { $this->gambits[] = $gambitClass; return $this; } /** * Set the full text gambit for this searcher. The full text gambit actually executes the search. * * @param string $gambitClass: The ::class attribute of the full test gambit you are adding. * This gambit must implement \Flarum\Search\GambitInterface * @return self */ public function setFullTextGambit(string $gambitClass): self { $this->fullTextGambit = $gambitClass; return $this; } /** * Add a callback through which to run all search queries after gambits have been applied. * * @param callable|string $callback * * The callback can be a closure or an invokable class, and should accept: * - \Flarum\Search\SearchState $search * - \Flarum\Query\QueryCriteria $criteria * * The callback should return void. * * @return self */ public function addSearchMutator($callback): self { $this->searchMutators[] = $callback; return $this; } public function extend(Container $container, Extension $extension = null) { if (! is_null($this->fullTextGambit)) { $container->extend('flarum.simple_search.fulltext_gambits', function ($oldFulltextGambits) { $oldFulltextGambits[$this->searcher] = $this->fullTextGambit; return $oldFulltextGambits; }); } $container->extend('flarum.simple_search.gambits', function ($oldGambits) { foreach ($this->gambits as $gambit) { $oldGambits[$this->searcher][] = $gambit; } return $oldGambits; }); $container->extend('flarum.simple_search.search_mutators', function ($oldMutators) { foreach ($this->searchMutators as $mutator) { $oldMutators[$this->searcher][] = $mutator; } return $oldMutators; }); } }