@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Partially use ApplicationSearch in main search

Summary:
Ref T4365. Primary search currently uses `PhabricatorSearchQuery` for storage, which is pretty much the same as `PhabricatorSavedQuery`, except that it's old and not used anywhere else anymore.

Maniphest used to also use this table, but no longer does after Septmeber, 2013. We need to retain the class so the migration can work.

This introduces `PhabricatorSearchApplicationSearchEngine` and `PhabricatorSearchDocumentQuery`, but they're both stubs that I just needed for technical reasons and/or to pass lint. The next couple patches will move logic into them and use ApplicationSearch properly.

Test Plan:
- Searched for stuff.
- Searched for stuff with filters.
- Searched for fulltext in Maniphest.
- Grepped for `PhabricatorSearchQuery`.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4365

Differential Revision: https://secure.phabricator.com/D8120

+116 -36
+4
src/__phutil_library_map__.php
··· 1941 1941 'PhabricatorSavedQueryQuery' => 'applications/search/query/PhabricatorSavedQueryQuery.php', 1942 1942 'PhabricatorScopedEnv' => 'infrastructure/env/PhabricatorScopedEnv.php', 1943 1943 'PhabricatorSearchAbstractDocument' => 'applications/search/index/PhabricatorSearchAbstractDocument.php', 1944 + 'PhabricatorSearchApplicationSearchEngine' => 'applications/search/query/PhabricatorSearchApplicationSearchEngine.php', 1944 1945 'PhabricatorSearchAttachController' => 'applications/search/controller/PhabricatorSearchAttachController.php', 1945 1946 'PhabricatorSearchBaseController' => 'applications/search/controller/PhabricatorSearchBaseController.php', 1946 1947 'PhabricatorSearchConfigOptions' => 'applications/search/config/PhabricatorSearchConfigOptions.php', ··· 1950 1951 'PhabricatorSearchDocument' => 'applications/search/storage/document/PhabricatorSearchDocument.php', 1951 1952 'PhabricatorSearchDocumentField' => 'applications/search/storage/document/PhabricatorSearchDocumentField.php', 1952 1953 'PhabricatorSearchDocumentIndexer' => 'applications/search/index/PhabricatorSearchDocumentIndexer.php', 1954 + 'PhabricatorSearchDocumentQuery' => 'applications/search/query/PhabricatorSearchDocumentQuery.php', 1953 1955 'PhabricatorSearchDocumentRelationship' => 'applications/search/storage/document/PhabricatorSearchDocumentRelationship.php', 1954 1956 'PhabricatorSearchEditController' => 'applications/search/controller/PhabricatorSearchEditController.php', 1955 1957 'PhabricatorSearchEngine' => 'applications/search/engine/PhabricatorSearchEngine.php', ··· 4686 4688 1 => 'PhabricatorPolicyInterface', 4687 4689 ), 4688 4690 'PhabricatorSavedQueryQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 4691 + 'PhabricatorSearchApplicationSearchEngine' => 'PhabricatorApplicationSearchEngine', 4689 4692 'PhabricatorSearchAttachController' => 'PhabricatorSearchBaseController', 4690 4693 'PhabricatorSearchBaseController' => 'PhabricatorController', 4691 4694 'PhabricatorSearchConfigOptions' => 'PhabricatorApplicationConfigOptions', ··· 4694 4697 'PhabricatorSearchDeleteController' => 'PhabricatorSearchBaseController', 4695 4698 'PhabricatorSearchDocument' => 'PhabricatorSearchDAO', 4696 4699 'PhabricatorSearchDocumentField' => 'PhabricatorSearchDAO', 4700 + 'PhabricatorSearchDocumentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 4697 4701 'PhabricatorSearchDocumentRelationship' => 'PhabricatorSearchDAO', 4698 4702 'PhabricatorSearchEditController' => 'PhabricatorSearchBaseController', 4699 4703 'PhabricatorSearchEngineElastic' => 'PhabricatorSearchEngine',
+4 -3
src/applications/home/controller/PhabricatorHomeMainController.php
··· 98 98 99 99 return $response; 100 100 } else if ($request->isFormPost()) { 101 - $query = new PhabricatorSearchQuery(); 102 - $query->setQuery($jump); 103 - $query->save(); 101 + $query = id(new PhabricatorSavedQuery()) 102 + ->setEngineClassName('PhabricatorSearchApplicationSearchEngine') 103 + ->setParameter('query', $jump) 104 + ->save(); 104 105 105 106 return id(new AphrontRedirectResponse()) 106 107 ->setURI('/search/'.$query->getQueryKey().'/');
+3 -2
src/applications/maniphest/query/ManiphestTaskQuery.php
··· 406 406 407 407 // In doing a fulltext search, we first find all the PHIDs that match the 408 408 // fulltext search, and then use that to limit the rest of the search 409 - $fulltext_query = new PhabricatorSearchQuery(); 410 - $fulltext_query->setQuery($this->fullTextSearch); 409 + $fulltext_query = id(new PhabricatorSavedQuery()) 410 + ->setEngineClassName('PhabricatorSearchApplicaionSearchEngine') 411 + ->setParameter('query', $this->fullTextSearch); 411 412 412 413 // NOTE: Setting this to something larger than 2^53 will raise errors in 413 414 // ElasticSearch, and billions of results won't fit in memory anyway.
+11 -6
src/applications/search/controller/PhabricatorSearchController.php
··· 21 21 $user = $request->getUser(); 22 22 23 23 if ($this->key) { 24 - $query = id(new PhabricatorSearchQuery())->loadOneWhere( 24 + $query = id(new PhabricatorSavedQuery())->loadOneWhere( 25 25 'queryKey = %s', 26 26 $this->key); 27 27 if (!$query) { 28 28 return new Aphront404Response(); 29 29 } 30 30 } else { 31 - $query = new PhabricatorSearchQuery(); 31 + $query = id(new PhabricatorSavedQuery()) 32 + ->setEngineClassName('PhabricatorSearchApplicationSearchEngine'); 32 33 33 34 if ($request->isFormPost()) { 34 35 $query_str = $request->getStr('query'); ··· 45 46 if ($response) { 46 47 return $response; 47 48 } else { 48 - $query->setQuery($query_str); 49 + $query->setParameter('query', $query_str); 49 50 50 51 if ($request->getStr('scope')) { 51 52 switch ($request->getStr('scope')) { ··· 101 102 } 102 103 } 103 104 104 - $query->save(); 105 + try { 106 + $query->save(); 107 + } catch (AphrontQueryDuplicateKeyException $ex) { 108 + // Someone has already executed this query. 109 + } 105 110 return id(new AphrontRedirectResponse()) 106 111 ->setURI('/search/'.$query->getQueryKey().'/'); 107 112 } ··· 157 162 id(new AphrontFormTextControl()) 158 163 ->setLabel('Search') 159 164 ->setName('query') 160 - ->setValue($query->getQuery())) 165 + ->setValue($query->getParameter('query'))) 161 166 ->appendChild( 162 167 id(new AphrontFormSelectControl()) 163 168 ->setLabel('Document Type') ··· 227 232 if (!$request->getInt('page')) { 228 233 $named = id(new PhabricatorObjectQuery()) 229 234 ->setViewer($user) 230 - ->withNames(array($query->getQuery())) 235 + ->withNames(array($query->getParameter('queyr'))) 231 236 ->execute(); 232 237 if ($named) { 233 238 $results = array_merge(array_keys($named), $results);
+3 -2
src/applications/search/controller/PhabricatorSearchSelectController.php
··· 16 16 $request = $this->getRequest(); 17 17 $user = $request->getUser(); 18 18 19 - $query = new PhabricatorSearchQuery(); 19 + $query = new PhabricatorSavedQuery(); 20 20 $query_str = $request->getStr('query'); 21 21 22 - $query->setQuery($query_str); 22 + $query->setEngineClassName('PhabricatorSearchApplicationSearchEngine'); 23 + $query->setParameter('query', $query_str); 23 24 $query->setParameter('type', $this->type); 24 25 25 26 switch ($request->getStr('filter')) {
+2 -4
src/applications/search/engine/PhabricatorSearchEngine.php
··· 5 5 * Base class for Phabricator search engine providers. Each engine must offer 6 6 * three capabilities: indexing, searching, and reconstruction (this can be 7 7 * stubbed out if an engine can't reasonably do it, it is used for debugging). 8 - * 9 - * @group search 10 8 */ 11 9 abstract class PhabricatorSearchEngine { 12 10 ··· 33 31 /** 34 32 * Execute a search query. 35 33 * 36 - * @param PhabricatorSearchQuery A query to execute. 34 + * @param PhabricatorSavedQuery A query to execute. 37 35 * @return list A list of matching PHIDs. 38 36 */ 39 - abstract public function executeSearch(PhabricatorSearchQuery $query); 37 + abstract public function executeSearch(PhabricatorSavedQuery $query); 40 38 41 39 }
+9 -10
src/applications/search/engine/PhabricatorSearchEngineElastic.php
··· 1 1 <?php 2 2 3 - /** 4 - * @group search 5 - */ 6 3 final class PhabricatorSearchEngineElastic extends PhabricatorSearchEngine { 7 4 private $uri; 8 5 private $timeout; ··· 94 91 return $doc; 95 92 } 96 93 97 - private function buildSpec(PhabricatorSearchQuery $query) { 94 + private function buildSpec(PhabricatorSavedQuery $query) { 98 95 $spec = array(); 99 96 $filter = array(); 100 97 101 - if ($query->getQuery() != '') { 98 + if ($query->getParameter('query') != '') { 102 99 $spec[] = array( 103 100 'field' => array( 104 - 'field.corpus' => $query->getQuery(), 101 + 'field.corpus' => $query->getParameter('query'), 105 102 ), 106 103 ); 107 104 } ··· 167 164 ); 168 165 } 169 166 170 - if (!$query->getQuery()) { 167 + if (!$query->getParameter('query')) { 171 168 $spec['sort'] = array( 172 169 array('dateCreated' => 'desc'), 173 170 ); ··· 179 176 return $spec; 180 177 } 181 178 182 - public function executeSearch(PhabricatorSearchQuery $query) { 179 + public function executeSearch(PhabricatorSavedQuery $query) { 183 180 $type = $query->getParameter('type'); 184 181 if ($type) { 185 182 $uri = "/phabricator/{$type}/_search"; ··· 197 194 // elasticsearch probably uses Lucene query syntax: 198 195 // http://lucene.apache.org/core/3_6_1/queryparsersyntax.html 199 196 // Try literal search if operator search fails. 200 - if (!$query->getQuery()) { 197 + if (!$query->getParameter('query')) { 201 198 throw $ex; 202 199 } 203 200 $query = clone $query; 204 - $query->setQuery(addcslashes($query->getQuery(), '+-&|!(){}[]^"~*?:\\')); 201 + $query->setQuery( 202 + addcslashes( 203 + $query->getParameter('query'), '+-&|!(){}[]^"~*?:\\')); 205 204 $response = $this->executeRequest($uri, $this->buildSpec($query)); 206 205 } 207 206
+3 -3
src/applications/search/engine/PhabricatorSearchEngineMySQL.php
··· 142 142 return $adoc; 143 143 } 144 144 145 - public function executeSearch(PhabricatorSearchQuery $query) { 145 + public function executeSearch(PhabricatorSavedQuery $query) { 146 146 147 147 $where = array(); 148 148 $join = array(); ··· 156 156 157 157 $conn_r = $dao_doc->establishConnection('r'); 158 158 159 - $q = $query->getQuery(); 159 + $q = $query->getParameter('query'); 160 160 161 161 if (strlen($q)) { 162 162 $join[] = qsprintf( ··· 281 281 282 282 protected function joinRelationship( 283 283 AphrontDatabaseConnection $conn, 284 - PhabricatorSearchQuery $query, 284 + PhabricatorSavedQuery $query, 285 285 $field, 286 286 $type) { 287 287
+49
src/applications/search/query/PhabricatorSearchApplicationSearchEngine.php
··· 1 + <?php 2 + 3 + final class PhabricatorSearchApplicationSearchEngine 4 + extends PhabricatorApplicationSearchEngine { 5 + 6 + public function buildSavedQueryFromRequest(AphrontRequest $request) { 7 + $saved = new PhabricatorSavedQuery(); 8 + 9 + return $saved; 10 + } 11 + 12 + public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 13 + $query = id(new PhabricatorSearchDocumentQuery()); 14 + 15 + return $query; 16 + } 17 + 18 + public function buildSearchForm( 19 + AphrontFormView $form, 20 + PhabricatorSavedQuery $saved_query) { 21 + return; 22 + } 23 + 24 + protected function getURI($path) { 25 + return '/search/'.$path; 26 + } 27 + 28 + public function getBuiltinQueryNames() { 29 + $names = array( 30 + 'all' => pht('All Documents'), 31 + ); 32 + 33 + return $names; 34 + } 35 + 36 + public function buildSavedQueryFromBuiltin($query_key) { 37 + 38 + $query = $this->newSavedQuery(); 39 + $query->setQueryKey($query_key); 40 + 41 + switch ($query_key) { 42 + case 'all': 43 + return $query; 44 + } 45 + 46 + return parent::buildSavedQueryFromBuiltin($query_key); 47 + } 48 + 49 + }
+14
src/applications/search/query/PhabricatorSearchDocumentQuery.php
··· 1 + <?php 2 + 3 + final class PhabricatorSearchDocumentQuery 4 + extends PhabricatorCursorPagedPolicyAwareQuery { 5 + 6 + protected function loadPage() { 7 + return array(); 8 + } 9 + 10 + public function getQueryApplicationClass() { 11 + return 'PhabricatorApplicationSearch'; 12 + } 13 + 14 + }
+12 -1
src/applications/search/storage/PhabricatorSearchQuery.php
··· 1 1 <?php 2 2 3 3 /** 4 - * @group search 4 + * Obsolete storage for saved search parameters. This class is no longer used; 5 + * it was obsoleted by the introduction of {@class:PhabricatorSavedQuery}. 6 + * 7 + * This class is retained only because one of the migrations 8 + * (`20130913.maniphest.1.migratesearch.php`) relies on it to migrate old saved 9 + * Maniphest searches to new infrastructure. We can remove this class and the 10 + * corresponding migration after installs have had a reasonable amount of time 11 + * to perform it. 12 + * 13 + * TODO: Remove this class after 2014-09-13, roughly. 14 + * 15 + * @deprecated 5 16 */ 6 17 final class PhabricatorSearchQuery extends PhabricatorSearchDAO { 7 18
+2 -5
src/applications/search/view/PhabricatorSearchResultView.php
··· 1 1 <?php 2 2 3 - /** 4 - * @group search 5 - */ 6 3 final class PhabricatorSearchResultView extends AphrontView { 7 4 8 5 private $handle; ··· 14 11 return $this; 15 12 } 16 13 17 - public function setQuery(PhabricatorSearchQuery $query) { 14 + public function setQuery(PhabricatorSavedQuery $query) { 18 15 $this->query = $query; 19 16 return $this; 20 17 } ··· 84 81 return $str; 85 82 } 86 83 87 - $query = $this->query->getQuery(); 84 + $query = $this->query->getParameter('query'); 88 85 89 86 $quoted_regexp = '/"([^"]*)"/'; 90 87 $matches = array(1 => array());