1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-25 00:02:41 +01:00

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
This commit is contained in:
Benjamin Kausch 2023-09-02 18:52:13 +02:00 committed by Benjamin Kausch
parent cef12d8dc2
commit dc10a7e69e
4 changed files with 28 additions and 30 deletions

View file

@ -0,0 +1,6 @@
<?php
// @phase worker
PhabricatorRebuildIndexesWorker::rebuildObjectsWithQuery(
'PhabricatorRepositoryQuery');

View file

@ -16,13 +16,16 @@ final class DiffusionRepositoryDatasource
}
public function loadResults() {
$viewer = $this->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();

View file

@ -9,7 +9,6 @@ final class PhabricatorRepositoryQuery
private $types;
private $uuids;
private $uris;
private $datasourceQuery;
private $slugs;
private $almanacServicePHIDs;
@ -124,11 +123,6 @@ final class PhabricatorRepositoryQuery
return $this;
}
public function withDatasourceQuery($query) {
$this->datasourceQuery = $query;
return $this;
}
public function withSlugs(array $slugs) {
$this->slugs = $slugs;
return $this;
@ -637,22 +631,6 @@ final class PhabricatorRepositoryQuery
$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) {
$where[] = qsprintf(
$conn,

View file

@ -7,10 +7,21 @@ final class PhabricatorRepositoryFulltextEngine
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());