Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / search / engineextension / PhabricatorFerretSearchEngineExtension.php
blob55b7c2225a9d3f74c6857601132407b67e029edc
1 <?php
3 final class PhabricatorFerretSearchEngineExtension
4 extends PhabricatorSearchEngineExtension {
6 const EXTENSIONKEY = 'ferret';
8 public function isExtensionEnabled() {
9 return true;
12 public function getExtensionName() {
13 return pht('Fulltext Search');
16 public function getExtensionOrder() {
17 return 1000;
20 public function supportsObject($object) {
21 return ($object instanceof PhabricatorFerretInterface);
24 public function applyConstraintsToQuery(
25 $object,
26 $query,
27 PhabricatorSavedQuery $saved,
28 array $map) {
30 if (!strlen($map['query'])) {
31 return;
34 $engine = $object->newFerretEngine();
36 $raw_query = $map['query'];
38 $compiler = id(new PhutilSearchQueryCompiler())
39 ->setEnableFunctions(true);
41 $raw_tokens = $compiler->newTokens($raw_query);
43 $fulltext_tokens = array();
44 foreach ($raw_tokens as $raw_token) {
45 $fulltext_token = id(new PhabricatorFulltextToken())
46 ->setToken($raw_token);
48 $fulltext_tokens[] = $fulltext_token;
51 $query->withFerretConstraint($engine, $fulltext_tokens);
54 public function getSearchFields($object) {
55 $fields = array();
57 $fields[] = id(new PhabricatorSearchTextField())
58 ->setKey('query')
59 ->setLabel(pht('Query'))
60 ->setDescription(
61 pht(
62 'Find objects matching a fulltext search query. See '.
63 '"Search User Guide" in the documentation for details.'));
65 return $fields;
68 public function getSearchAttachments($object) {
69 return array();