@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.

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

authored by

Benjamin Kausch and committed by
Benjamin Kausch
dc10a7e6 cef12d8d

+28 -30
+6
resources/sql/autopatches/20230902.repository.01.rebuild-index.php
··· 1 + <?php 2 + 3 + // @phase worker 4 + 5 + PhabricatorRebuildIndexesWorker::rebuildObjectsWithQuery( 6 + 'PhabricatorRepositoryQuery');
+9 -6
src/applications/diffusion/typeahead/DiffusionRepositoryDatasource.php
··· 16 16 } 17 17 18 18 public function loadResults() { 19 - $viewer = $this->getViewer(); 20 - $raw_query = $this->getRawQuery(); 19 + $query = id(new PhabricatorRepositoryQuery()) 20 + ->setViewer($this->getViewer()); 21 + 22 + $this->applyFerretConstraints( 23 + $query, 24 + id(new PhabricatorRepository())->newFerretEngine(), 25 + 'title', 26 + $this->getRawQuery()); 21 27 22 - $query = id(new PhabricatorRepositoryQuery()) 23 - ->setOrder('name') 24 - ->withDatasourceQuery($raw_query); 25 - $repos = $this->executeQuery($query); 28 + $repos = $query->execute(); 26 29 27 30 $type_icon = id(new PhabricatorRepositoryRepositoryPHIDType()) 28 31 ->getTypeIcon();
-22
src/applications/repository/query/PhabricatorRepositoryQuery.php
··· 9 9 private $types; 10 10 private $uuids; 11 11 private $uris; 12 - private $datasourceQuery; 13 12 private $slugs; 14 13 private $almanacServicePHIDs; 15 14 ··· 121 120 122 121 public function withURIs(array $uris) { 123 122 $this->uris = $uris; 124 - return $this; 125 - } 126 - 127 - public function withDatasourceQuery($query) { 128 - $this->datasourceQuery = $query; 129 123 return $this; 130 124 } 131 125 ··· 635 629 $conn, 636 630 'r.uuid IN (%Ls)', 637 631 $this->uuids); 638 - } 639 - 640 - if (phutil_nonempty_string($this->datasourceQuery)) { 641 - // This handles having "rP" match callsigns starting with "P...". 642 - $query = trim($this->datasourceQuery); 643 - if (preg_match('/^r/', $query)) { 644 - $callsign = substr($query, 1); 645 - } else { 646 - $callsign = $query; 647 - } 648 - $where[] = qsprintf( 649 - $conn, 650 - 'r.name LIKE %> OR r.callsign LIKE %> OR r.repositorySlug LIKE %>', 651 - $query, 652 - $callsign, 653 - $query); 654 632 } 655 633 656 634 if ($this->slugs !== null) {
+13 -2
src/applications/repository/search/PhabricatorRepositoryFulltextEngine.php
··· 7 7 PhabricatorSearchAbstractDocument $document, 8 8 $object) { 9 9 $repo = $object; 10 - $document->setDocumentTitle($repo->getName()); 10 + 11 + $title_fields = array( 12 + $repo->getName(), 13 + $repo->getRepositorySlug(), 14 + ); 15 + $callsign = $repo->getCallsign(); 16 + if ($callsign) { 17 + $title_fields[] = $callsign; 18 + $title_fields[] = 'r'.$callsign; 19 + } 20 + 21 + $document->setDocumentTitle(implode("\n", $title_fields)); 11 22 $document->addField( 12 23 PhabricatorSearchDocumentFieldType::FIELD_BODY, 13 - $repo->getRepositorySlug()."\n".$repo->getDetail('description')); 24 + $repo->getDetail('description')); 14 25 15 26 $document->setDocumentCreated($repo->getDateCreated()); 16 27 $document->setDocumentModified($repo->getDateModified());