From dc10a7e69ea33fd4b589f0d9e8c9921bc6f94765 Mon Sep 17 00:00:00 2001 From: Benjamin Kausch Date: Sat, 02 Sep 2023 16:52:13 +0000 Subject: [PATCH] Implement ferret engine in typeahead datasource query for repos Summary: This broadens the typeahead datasource search for repos. Before this patch a repository named "Alligator Simulator" would not be found with the search string "simu...". This is patched with the ferret engine search and indexing features. See T15583 Test Plan: Create repositories with titles with 2 or more words. Search for these repos with the global typeahead search. The search term should begin with the second/third/n-th word of the repo title. Reviewers: O1 Blessed Committers, avivey Reviewed By: O1 Blessed Committers, avivey Subscribers: avivey, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15583 Differential Revision: https://we.phorge.it/D25430 --- resources/sql/autopatches/20230902.repository.01.rebuild-index.php | 6 ++++++ src/applications/diffusion/typeahead/DiffusionRepositoryDatasource.php | 15 +++++++++------ src/applications/repository/query/PhabricatorRepositoryQuery.php | 22 ---------------------- src/applications/repository/search/PhabricatorRepositoryFulltextEngine.php | 15 +++++++++++++-- 4 file(s) changed, 28 insertion(s)(+), 30 deletion(s)(-) diff --git a/resources/sql/autopatches/20230902.repository.01.rebuild-index.php b/resources/sql/autopatches/20230902.repository.01.rebuild-index.php new file mode 100644 --- /dev/null +++ b/resources/sql/autopatches/20230902.repository.01.rebuild-index.php @@ -0,0 +1,6 @@ +getViewer(); - $raw_query = $this->getRawQuery(); - $query = id(new PhabricatorRepositoryQuery()) - ->setOrder('name') - ->withDatasourceQuery($raw_query); - $repos = $this->executeQuery($query); + ->setViewer($this->getViewer()); + + $this->applyFerretConstraints( + $query, + id(new PhabricatorRepository())->newFerretEngine(), + 'title', + $this->getRawQuery()); + + $repos = $query->execute(); $type_icon = id(new PhabricatorRepositoryRepositoryPHIDType()) ->getTypeIcon(); diff --git a/src/applications/repository/query/PhabricatorRepositoryQuery.php b/src/applications/repository/query/PhabricatorRepositoryQuery.php --- a/src/applications/repository/query/PhabricatorRepositoryQuery.php +++ b/src/applications/repository/query/PhabricatorRepositoryQuery.php @@ -9,7 +9,6 @@ private $types; private $uuids; private $uris; - private $datasourceQuery; private $slugs; private $almanacServicePHIDs; @@ -121,11 +120,6 @@ public function withURIs(array $uris) { $this->uris = $uris; - return $this; - } - - public function withDatasourceQuery($query) { - $this->datasourceQuery = $query; return $this; } @@ -635,22 +629,6 @@ $conn, 'r.uuid IN (%Ls)', $this->uuids); - } - - if (phutil_nonempty_string($this->datasourceQuery)) { - // This handles having "rP" match callsigns starting with "P...". - $query = trim($this->datasourceQuery); - if (preg_match('/^r/', $query)) { - $callsign = substr($query, 1); - } else { - $callsign = $query; - } - $where[] = qsprintf( - $conn, - 'r.name LIKE %> OR r.callsign LIKE %> OR r.repositorySlug LIKE %>', - $query, - $callsign, - $query); } if ($this->slugs !== null) { diff --git a/src/applications/repository/search/PhabricatorRepositoryFulltextEngine.php b/src/applications/repository/search/PhabricatorRepositoryFulltextEngine.php --- a/src/applications/repository/search/PhabricatorRepositoryFulltextEngine.php +++ b/src/applications/repository/search/PhabricatorRepositoryFulltextEngine.php @@ -7,10 +7,21 @@ PhabricatorSearchAbstractDocument $document, $object) { $repo = $object; - $document->setDocumentTitle($repo->getName()); + + $title_fields = array( + $repo->getName(), + $repo->getRepositorySlug(), + ); + $callsign = $repo->getCallsign(); + if ($callsign) { + $title_fields[] = $callsign; + $title_fields[] = 'r'.$callsign; + } + + $document->setDocumentTitle(implode("\n", $title_fields)); $document->addField( PhabricatorSearchDocumentFieldType::FIELD_BODY, - $repo->getRepositorySlug()."\n".$repo->getDetail('description')); + $repo->getDetail('description')); $document->setDocumentCreated($repo->getDateCreated()); $document->setDocumentModified($repo->getDateModified()); -- tangled.sh