mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-09 16:32:39 +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:
parent
cef12d8dc2
commit
dc10a7e69e
4 changed files with 28 additions and 30 deletions
|
@ -0,0 +1,6 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// @phase worker
|
||||||
|
|
||||||
|
PhabricatorRebuildIndexesWorker::rebuildObjectsWithQuery(
|
||||||
|
'PhabricatorRepositoryQuery');
|
|
@ -16,13 +16,16 @@ final class DiffusionRepositoryDatasource
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadResults() {
|
public function loadResults() {
|
||||||
$viewer = $this->getViewer();
|
|
||||||
$raw_query = $this->getRawQuery();
|
|
||||||
|
|
||||||
$query = id(new PhabricatorRepositoryQuery())
|
$query = id(new PhabricatorRepositoryQuery())
|
||||||
->setOrder('name')
|
->setViewer($this->getViewer());
|
||||||
->withDatasourceQuery($raw_query);
|
|
||||||
$repos = $this->executeQuery($query);
|
$this->applyFerretConstraints(
|
||||||
|
$query,
|
||||||
|
id(new PhabricatorRepository())->newFerretEngine(),
|
||||||
|
'title',
|
||||||
|
$this->getRawQuery());
|
||||||
|
|
||||||
|
$repos = $query->execute();
|
||||||
|
|
||||||
$type_icon = id(new PhabricatorRepositoryRepositoryPHIDType())
|
$type_icon = id(new PhabricatorRepositoryRepositoryPHIDType())
|
||||||
->getTypeIcon();
|
->getTypeIcon();
|
||||||
|
|
|
@ -9,7 +9,6 @@ final class PhabricatorRepositoryQuery
|
||||||
private $types;
|
private $types;
|
||||||
private $uuids;
|
private $uuids;
|
||||||
private $uris;
|
private $uris;
|
||||||
private $datasourceQuery;
|
|
||||||
private $slugs;
|
private $slugs;
|
||||||
private $almanacServicePHIDs;
|
private $almanacServicePHIDs;
|
||||||
|
|
||||||
|
@ -124,11 +123,6 @@ final class PhabricatorRepositoryQuery
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function withDatasourceQuery($query) {
|
|
||||||
$this->datasourceQuery = $query;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function withSlugs(array $slugs) {
|
public function withSlugs(array $slugs) {
|
||||||
$this->slugs = $slugs;
|
$this->slugs = $slugs;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -637,22 +631,6 @@ final class PhabricatorRepositoryQuery
|
||||||
$this->uuids);
|
$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) {
|
if ($this->slugs !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn,
|
$conn,
|
||||||
|
|
|
@ -7,10 +7,21 @@ final class PhabricatorRepositoryFulltextEngine
|
||||||
PhabricatorSearchAbstractDocument $document,
|
PhabricatorSearchAbstractDocument $document,
|
||||||
$object) {
|
$object) {
|
||||||
$repo = $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(
|
$document->addField(
|
||||||
PhabricatorSearchDocumentFieldType::FIELD_BODY,
|
PhabricatorSearchDocumentFieldType::FIELD_BODY,
|
||||||
$repo->getRepositorySlug()."\n".$repo->getDetail('description'));
|
$repo->getDetail('description'));
|
||||||
|
|
||||||
$document->setDocumentCreated($repo->getDateCreated());
|
$document->setDocumentCreated($repo->getDateCreated());
|
||||||
$document->setDocumentModified($repo->getDateModified());
|
$document->setDocumentModified($repo->getDateModified());
|
||||||
|
|
Loading…
Reference in a new issue