Skip to content

Commit dc10a7e

Browse files
committed
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
1 parent cef12d8 commit dc10a7e

File tree

4 files changed

+28
-30
lines changed

4 files changed

+28
-30
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
// @phase worker
4+
5+
PhabricatorRebuildIndexesWorker::rebuildObjectsWithQuery(
6+
'PhabricatorRepositoryQuery');

src/applications/diffusion/typeahead/DiffusionRepositoryDatasource.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ public function getDatasourceApplicationClass() {
1616
}
1717

1818
public function loadResults() {
19-
$viewer = $this->getViewer();
20-
$raw_query = $this->getRawQuery();
21-
2219
$query = id(new PhabricatorRepositoryQuery())
23-
->setOrder('name')
24-
->withDatasourceQuery($raw_query);
25-
$repos = $this->executeQuery($query);
20+
->setViewer($this->getViewer());
21+
22+
$this->applyFerretConstraints(
23+
$query,
24+
id(new PhabricatorRepository())->newFerretEngine(),
25+
'title',
26+
$this->getRawQuery());
27+
28+
$repos = $query->execute();
2629

2730
$type_icon = id(new PhabricatorRepositoryRepositoryPHIDType())
2831
->getTypeIcon();

src/applications/repository/query/PhabricatorRepositoryQuery.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ final class PhabricatorRepositoryQuery
99
private $types;
1010
private $uuids;
1111
private $uris;
12-
private $datasourceQuery;
1312
private $slugs;
1413
private $almanacServicePHIDs;
1514

@@ -124,11 +123,6 @@ public function withURIs(array $uris) {
124123
return $this;
125124
}
126125

127-
public function withDatasourceQuery($query) {
128-
$this->datasourceQuery = $query;
129-
return $this;
130-
}
131-
132126
public function withSlugs(array $slugs) {
133127
$this->slugs = $slugs;
134128
return $this;
@@ -637,22 +631,6 @@ protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
637631
$this->uuids);
638632
}
639633

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-
}
655-
656634
if ($this->slugs !== null) {
657635
$where[] = qsprintf(
658636
$conn,

src/applications/repository/search/PhabricatorRepositoryFulltextEngine.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,21 @@ protected function buildAbstractDocument(
77
PhabricatorSearchAbstractDocument $document,
88
$object) {
99
$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));
1122
$document->addField(
1223
PhabricatorSearchDocumentFieldType::FIELD_BODY,
13-
$repo->getRepositorySlug()."\n".$repo->getDetail('description'));
24+
$repo->getDetail('description'));
1425

1526
$document->setDocumentCreated($repo->getDateCreated());
1627
$document->setDocumentModified($repo->getDateModified());

0 commit comments

Comments
 (0)