diff --git a/src/applications/search/compiler/PhutilSearchQueryCompiler.php b/src/applications/search/compiler/PhutilSearchQueryCompiler.php --- a/src/applications/search/compiler/PhutilSearchQueryCompiler.php +++ b/src/applications/search/compiler/PhutilSearchQueryCompiler.php @@ -29,19 +29,32 @@ return $this; } + /** + * @return PhutilSearchStemmer + */ public function getStemmer() { return $this->stemmer; } + /** + * @param bool + */ public function setEnableFunctions($enable_functions) { $this->enableFunctions = $enable_functions; return $this; } + /** + * @return bool + */ public function getEnableFunctions() { return $this->enableFunctions; } + /** + * @param array $tokens + * @return string|null + */ public function compileQuery(array $tokens) { assert_instances_of($tokens, 'PhutilSearchQueryToken'); @@ -53,6 +66,10 @@ return $this->compileRenderedTokens($result); } + /** + * @param array $tokens + * @return string|null + */ public function compileLiteralQuery(array $tokens) { assert_instances_of($tokens, 'PhutilSearchQueryToken'); @@ -67,6 +84,10 @@ return $this->compileRenderedTokens($result); } + /** + * @param array $tokens + * @return string|null + */ public function compileStemmedQuery(array $tokens) { assert_instances_of($tokens, 'PhutilSearchQueryToken'); @@ -81,6 +102,9 @@ return $this->compileRenderedTokens($result); } + /** + * @return string|null + */ private function compileRenderedTokens(array $list) { if (!$list) { return null; @@ -90,6 +114,9 @@ return implode(' ', $list); } + /** + * @return PhutilSearchQueryToken[] + */ public function newTokens($query) { $results = $this->tokenizeQuery($query); @@ -101,6 +128,12 @@ return $tokens; } + /** + * @param string $query Search string or part of the search string + * @return array An array consisting of array elements like + * {"operator":"and","quoted":false,"value":"get","raw":"get", + * "function":null} + */ private function tokenizeQuery($query) { $maximum_bytes = 1024; if ($query === null) { diff --git a/src/applications/search/compiler/PhutilSearchQueryToken.php b/src/applications/search/compiler/PhutilSearchQueryToken.php --- a/src/applications/search/compiler/PhutilSearchQueryToken.php +++ b/src/applications/search/compiler/PhutilSearchQueryToken.php @@ -7,6 +7,9 @@ private $operator; private $function; + /** + * @return PhutilSearchQueryToken + */ public static function newFromDictionary(array $dictionary) { $token = new self(); diff --git a/src/applications/search/compiler/PhutilSearchStemmer.php b/src/applications/search/compiler/PhutilSearchStemmer.php --- a/src/applications/search/compiler/PhutilSearchStemmer.php +++ b/src/applications/search/compiler/PhutilSearchStemmer.php @@ -3,11 +3,22 @@ final class PhutilSearchStemmer extends Phobject { + /** + * Perform normalization and stemming on input token + * @param string $token Input token + * @return string Either stemmed token, or original input if token is too + * short (<3 characters) or if token contains certain punctuation elements + */ public function stemToken($token) { $token = $this->normalizeToken($token); return $this->applyStemmer($token); } + /** + * Perform normalization and stemming on input corpus + * @param string $corpus Input corpus + * @return string Stemmed corpus + */ public function stemCorpus($corpus) { $corpus = $this->normalizeCorpus($corpus); $tokens = preg_split('/[^a-zA-Z0-9\x7F-\xFF._]+/', $corpus); @@ -31,15 +42,29 @@ return implode(' ', $stems); } + /** + * Internally convert token to lower case in a UTF8-aware way. + * @param string $token Input token. + * @return string Input token, in some semblance of lower case. + */ private function normalizeToken($token) { return phutil_utf8_strtolower($token); } + /** + * Internally convert corpus to lower case in a UTF8-aware way. + * @param string $corpus Input corpus. + * @return string Input corpus, in some semblance of lower case. + */ private function normalizeCorpus($corpus) { return phutil_utf8_strtolower($corpus); } /** + * Internally pass normalized tokens to Porter to perform stemming. Or not. + * @param string $normalized_token Lower case token + * @return string Either stemmed token, or original input if token is too + * short (<3 characters) or if token contains certain punctuation elements * @phutil-external-symbol class Porter */ private function applyStemmer($normalized_token) { diff --git a/src/applications/search/fulltextstorage/PhabricatorFerretFulltextStorageEngine.php b/src/applications/search/fulltextstorage/PhabricatorFerretFulltextStorageEngine.php --- a/src/applications/search/fulltextstorage/PhabricatorFerretFulltextStorageEngine.php +++ b/src/applications/search/fulltextstorage/PhabricatorFerretFulltextStorageEngine.php @@ -6,6 +6,9 @@ private $fulltextTokens = array(); private $engineLimits; + /** + * @return string Engine identifier string: "mysql" + */ public function getEngineIdentifier() { return 'mysql'; } diff --git a/src/applications/search/query/PhabricatorFulltextResultSet.php b/src/applications/search/query/PhabricatorFulltextResultSet.php --- a/src/applications/search/query/PhabricatorFulltextResultSet.php +++ b/src/applications/search/query/PhabricatorFulltextResultSet.php @@ -14,11 +14,17 @@ return $this->phids; } + /** + * @param array + */ public function setFulltextTokens($fulltext_tokens) { $this->fulltextTokens = $fulltext_tokens; return $this; } + /** + * @return array + */ public function getFulltextTokens() { return $this->fulltextTokens; } diff --git a/src/applications/search/query/PhabricatorFulltextToken.php b/src/applications/search/query/PhabricatorFulltextToken.php --- a/src/applications/search/query/PhabricatorFulltextToken.php +++ b/src/applications/search/query/PhabricatorFulltextToken.php @@ -11,6 +11,9 @@ return $this; } + /** + * @return PhutilSearchQueryToken + */ public function getToken() { return $this->token; } diff --git a/src/applications/search/query/PhabricatorSearchDocumentQuery.php b/src/applications/search/query/PhabricatorSearchDocumentQuery.php --- a/src/applications/search/query/PhabricatorSearchDocumentQuery.php +++ b/src/applications/search/query/PhabricatorSearchDocumentQuery.php @@ -26,6 +26,9 @@ return $this->getRequiredCapabilities(); } + /** + * @return PhabricatorFulltextResultSet + */ public function getFulltextResultSet() { if (!$this->fulltextResultSet) { throw new PhutilInvalidStateException('execute'); @@ -39,6 +42,11 @@ $this->fulltextResultSet = null; } + /** + * Load a raw page of results. + * + * @return list PHIDs of the search result objects as array keys. + */ protected function loadPage() { // NOTE: The offset and limit information in the inherited properties of // this object represent a policy-filtered offset and limit, but the diff --git a/src/infrastructure/cluster/search/PhabricatorElasticsearchHost.php b/src/infrastructure/cluster/search/PhabricatorElasticsearchHost.php --- a/src/infrastructure/cluster/search/PhabricatorElasticsearchHost.php +++ b/src/infrastructure/cluster/search/PhabricatorElasticsearchHost.php @@ -20,10 +20,16 @@ return $this; } + /** + * @return string Display name of the search host: "Elasticsearch" + */ public function getDisplayName() { return pht('Elasticsearch'); } + /** + * @return string[] Get a list of fields to show in the status overview UI + */ public function getStatusViewColumns() { return array( pht('Protocol') => $this->getProtocol(), @@ -40,6 +46,9 @@ return $this; } + /** + * @return string Search host protocol, by default "http" + */ public function getProtocol() { return $this->protocol; } @@ -62,6 +71,9 @@ return $this->version; } + /** + * @return PhutilURI + */ public function getURI($to_path = null) { $uri = id(new PhutilURI('http://'.$this->getHost())) ->setProtocol($this->getProtocol()) diff --git a/src/infrastructure/cluster/search/PhabricatorMySQLSearchHost.php b/src/infrastructure/cluster/search/PhabricatorMySQLSearchHost.php --- a/src/infrastructure/cluster/search/PhabricatorMySQLSearchHost.php +++ b/src/infrastructure/cluster/search/PhabricatorMySQLSearchHost.php @@ -9,10 +9,16 @@ return $this; } + /** + * @return string Display name of the search host: "MySQL" + */ public function getDisplayName() { return 'MySQL'; } + /** + * @return string[] Get a list of fields to show in the status overview UI + */ public function getStatusViewColumns() { return array( pht('Protocol') => 'mysql', @@ -20,6 +26,9 @@ ); } + /** + * @return string Search host protocol: "mysql" + */ public function getProtocol() { return 'mysql'; } diff --git a/src/infrastructure/cluster/search/PhabricatorSearchService.php b/src/infrastructure/cluster/search/PhabricatorSearchService.php --- a/src/infrastructure/cluster/search/PhabricatorSearchService.php +++ b/src/infrastructure/cluster/search/PhabricatorSearchService.php @@ -26,6 +26,8 @@ /** * @throws Exception + * @return PhabricatorSearchHost An instance of a subclass of + * PhabricatorSearchHost */ public function newHost($config) { $host = clone($this->hostType); @@ -35,14 +37,24 @@ return $host; } + /** + * @return PhabricatorFulltextStorageEngine A subclass of + * PhabricatorFulltextStorageEngine + */ public function getEngine() { return $this->engine; } + /** + * @return string Display name of the search host, e.g. "MySQL" + */ public function getDisplayName() { return $this->hostType->getDisplayName(); } + /** + * @return string[] Get a list of fields to show in the status overview UI + */ public function getStatusViewColumns() { return $this->hostType->getStatusViewColumns(); } @@ -66,6 +78,9 @@ } + /** + * @return string[] + */ public function getConfig() { return $this->config; } @@ -249,6 +264,10 @@ return $result_set->getPHIDs(); } + /** + * @param PhabricatorSavedQuery $query + * @return PhabricatorFulltextResultSet + */ public static function newResultSet(PhabricatorSavedQuery $query) { $exceptions = array(); // try all services until one succeeds