3 abstract class PhabricatorFerretEngine
extends Phobject
{
5 private $fieldMap = array();
6 private $ferretFunctions;
7 private $templateObject;
9 abstract public function getApplicationName();
10 abstract public function getScopeName();
11 abstract public function newSearchEngine();
13 public function getDefaultFunctionKey() {
17 public function getObjectTypeRelevance() {
21 final public function getFunctionForName($raw_name) {
22 if (isset($this->fieldMap
[$raw_name])) {
23 return $this->fieldMap
[$raw_name];
27 FerretSearchFunction
::getNormalizedFunctionName($raw_name);
29 if ($this->ferretFunctions
=== null) {
30 $functions = FerretSearchFunction
::newFerretSearchFunctions();
31 $this->ferretFunctions
= $functions;
34 if (!isset($this->ferretFunctions
[$normalized_name])) {
35 throw new PhutilSearchQueryCompilerSyntaxException(
37 'Unknown search function "%s". Supported functions are: %s. '.
38 '(To search for a term containing a colon, surround the term '.
41 implode(', ', array_keys($this->ferretFunctions
))));
44 $function = $this->ferretFunctions
[$normalized_name];
45 $this->fieldMap
[$raw_name] = $function;
47 return $this->fieldMap
[$raw_name];
50 public function newStemmer() {
51 return new PhutilSearchStemmer();
54 public function newTermsCorpus($raw_corpus) {
94 // NOTE: Single quotes divide terms only if they're at a word boundary.
95 // In contractions, like "whom'st've", the entire word is a single term.
96 $term_corpus = preg_replace('/(^| )[\']+/', ' ', $term_corpus);
97 $term_corpus = preg_replace('/[\']+( |$)/', ' ', $term_corpus);
99 $term_corpus = preg_replace('/\s+/u', ' ', $term_corpus);
100 $term_corpus = trim($term_corpus, ' ');
102 if (strlen($term_corpus)) {
103 $term_corpus = ' '.$term_corpus.' ';
109 /* -( Schema )------------------------------------------------------------- */
111 public function getDocumentTableName() {
112 $application = $this->getApplicationName();
113 $scope = $this->getScopeName();
115 return "{$application}_{$scope}_fdocument";
118 public function getDocumentSchemaColumns() {
121 'objectPHID' => 'phid',
122 'isClosed' => 'bool',
123 'authorPHID' => 'phid?',
124 'ownerPHID' => 'phid?',
125 'epochCreated' => 'epoch',
126 'epochModified' => 'epoch',
130 public function getDocumentSchemaKeys() {
133 'columns' => array('id'),
136 'key_object' => array(
137 'columns' => array('objectPHID'),
140 'key_author' => array(
141 'columns' => array('authorPHID'),
143 'key_owner' => array(
144 'columns' => array('ownerPHID'),
146 'key_created' => array(
147 'columns' => array('epochCreated'),
149 'key_modified' => array(
150 'columns' => array('epochModified'),
155 public function getFieldTableName() {
156 $application = $this->getApplicationName();
157 $scope = $this->getScopeName();
159 return "{$application}_{$scope}_ffield";
162 public function getFieldSchemaColumns() {
165 'documentID' => 'uint32',
166 'fieldKey' => 'text4',
167 'rawCorpus' => 'sort',
168 'termCorpus' => 'sort',
169 'normalCorpus' => 'sort',
173 public function getFieldSchemaKeys() {
176 'columns' => array('id'),
179 'key_documentfield' => array(
180 'columns' => array('documentID', 'fieldKey'),
186 public function getNgramsTableName() {
187 $application = $this->getApplicationName();
188 $scope = $this->getScopeName();
190 return "{$application}_{$scope}_fngrams";
193 public function getNgramsSchemaColumns() {
196 'documentID' => 'uint32',
201 public function getNgramsSchemaKeys() {
204 'columns' => array('id'),
207 'key_ngram' => array(
208 'columns' => array('ngram', 'documentID'),
210 'key_object' => array(
211 'columns' => array('documentID'),
216 public function getCommonNgramsTableName() {
217 $application = $this->getApplicationName();
218 $scope = $this->getScopeName();
220 return "{$application}_{$scope}_fngrams_common";
223 public function getCommonNgramsSchemaColumns() {
227 'needsCollection' => 'bool',
231 public function getCommonNgramsSchemaKeys() {
234 'columns' => array('id'),
237 'key_ngram' => array(
238 'columns' => array('ngram'),
241 'key_collect' => array(
242 'columns' => array('needsCollection'),