Permalink
Browse files

Add repositories to fulltext search index.

Summary:
This implements a simplistic `PhabricatorRepositoryFulltextEngine`
Currently only the repository name, description, timestamps and
status are indexed.

Note: I had to change the `search index` workflow to disambiguate
PhabricatorRepository from PhabricatorRepositoryCommit

Test Plan:
* ran `./bin/search index --type PhabricatorRepository --force`
 * searched for some repositories. Saw reasonable results matching on either title or description.
* Edited a repository in the web ui
 * Added unique key words to the repo description.
 * I was then able to find that repo by searching for the new keywords.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin

Tags: #search, #diffusion

Differential Revision: https://secure.phabricator.com/D17300
1 parent 9e2ab4f commit 9e2f263bb49c3fdc433fbec63ca849ff9e1fa2b6 @20after4 20after4 committed with 20after4 Mar 28, 2017
@@ -3660,6 +3660,7 @@
'PhabricatorRepositoryDiscoveryEngine' => 'applications/repository/engine/PhabricatorRepositoryDiscoveryEngine.php',
'PhabricatorRepositoryEditor' => 'applications/repository/editor/PhabricatorRepositoryEditor.php',
'PhabricatorRepositoryEngine' => 'applications/repository/engine/PhabricatorRepositoryEngine.php',
+ 'PhabricatorRepositoryFulltextEngine' => 'applications/repository/search/PhabricatorRepositoryFulltextEngine.php',
'PhabricatorRepositoryGitCommitChangeParserWorker' => 'applications/repository/worker/commitchangeparser/PhabricatorRepositoryGitCommitChangeParserWorker.php',
'PhabricatorRepositoryGitCommitMessageParserWorker' => 'applications/repository/worker/commitmessageparser/PhabricatorRepositoryGitCommitMessageParserWorker.php',
'PhabricatorRepositoryGitLFSRef' => 'applications/repository/storage/PhabricatorRepositoryGitLFSRef.php',
@@ -8910,6 +8911,7 @@
'PhabricatorProjectInterface',
'PhabricatorSpacesInterface',
'PhabricatorConduitResultInterface',
+ 'PhabricatorFulltextInterface',
),
'PhabricatorRepositoryAuditRequest' => array(
'PhabricatorRepositoryDAO',
@@ -8951,6 +8953,7 @@
'PhabricatorRepositoryDiscoveryEngine' => 'PhabricatorRepositoryEngine',
'PhabricatorRepositoryEditor' => 'PhabricatorApplicationTransactionEditor',
'PhabricatorRepositoryEngine' => 'Phobject',
+ 'PhabricatorRepositoryFulltextEngine' => 'PhabricatorFulltextEngine',
'PhabricatorRepositoryGitCommitChangeParserWorker' => 'PhabricatorRepositoryCommitChangeParserWorker',
'PhabricatorRepositoryGitCommitMessageParserWorker' => 'PhabricatorRepositoryCommitMessageParserWorker',
'PhabricatorRepositoryGitLFSRef' => array(
@@ -0,0 +1,27 @@
+<?php
+
+final class PhabricatorRepositoryFulltextEngine
+ extends PhabricatorFulltextEngine {
+
+ protected function buildAbstractDocument(
+ PhabricatorSearchAbstractDocument $document,
+ $object) {
+ $repo = $object;
+ $document->setDocumentTitle($repo->getName());
+ $document->addField(
+ PhabricatorSearchDocumentFieldType::FIELD_BODY,
+ $repo->getRepositorySlug()."\n".$repo->getDetail('description'));
+
+ $document->setDocumentCreated($repo->getDateCreated());
+ $document->setDocumentModified($repo->getDateModified());
+
+ $document->addRelationship(
+ $repo->isTracked()
+ ? PhabricatorSearchRelationship::RELATIONSHIP_OPEN
+ : PhabricatorSearchRelationship::RELATIONSHIP_CLOSED,
+ $repo->getPHID(),
+ PhabricatorRepositoryRepositoryPHIDType::TYPECONST,
+ PhabricatorTime::getNow());
+ }
+
+}
@@ -14,7 +14,8 @@
PhabricatorDestructibleInterface,
PhabricatorProjectInterface,
PhabricatorSpacesInterface,
- PhabricatorConduitResultInterface {
+ PhabricatorConduitResultInterface,
+ PhabricatorFulltextInterface {
/**
* Shortest hash we'll recognize in raw "a829f32" form.
@@ -2572,4 +2573,11 @@ public function getConduitSearchAttachments() {
);
}
+/* -( PhabricatorFulltextInterface )--------------------------------------- */
+
+
+ public function newFulltextEngine() {
+ return new PhabricatorRepositoryFulltextEngine();
+ }
+
}
@@ -158,9 +158,15 @@ private function loadPHIDsByTypes($type) {
$object_class = get_class($object);
$normalized_class = phutil_utf8_strtolower($object_class);
+ if ($normalized_class === $normalized_type) {
+ $matches = array($object_class => $object);
+ break;
+ }
+
if (!strlen($type) ||
strpos($normalized_class, $normalized_type) !== false) {
$matches[$object_class] = $object;
+
}
}

0 comments on commit 9e2f263

Please sign in to comment.