From 9e2f263bb49c3fdc433fbec63ca849ff9e1fa2b6 Mon Sep 17 00:00:00 2001 From: Mukunda Modell Date: Tue, 28 Mar 2017 07:58:22 +0000 Subject: [PATCH] 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 --- src/__phutil_library_map__.php | 3 +++ .../PhabricatorRepositoryFulltextEngine.php | 27 +++++++++++++++++++ .../storage/PhabricatorRepository.php | 10 ++++++- ...abricatorSearchManagementIndexWorkflow.php | 6 +++++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/applications/repository/search/PhabricatorRepositoryFulltextEngine.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 7c233cb93a..5d9e3de268 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -3660,6 +3660,7 @@ phutil_register_library_map(array( '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 @@ phutil_register_library_map(array( 'PhabricatorProjectInterface', 'PhabricatorSpacesInterface', 'PhabricatorConduitResultInterface', + 'PhabricatorFulltextInterface', ), 'PhabricatorRepositoryAuditRequest' => array( 'PhabricatorRepositoryDAO', @@ -8951,6 +8953,7 @@ phutil_register_library_map(array( 'PhabricatorRepositoryDiscoveryEngine' => 'PhabricatorRepositoryEngine', 'PhabricatorRepositoryEditor' => 'PhabricatorApplicationTransactionEditor', 'PhabricatorRepositoryEngine' => 'Phobject', + 'PhabricatorRepositoryFulltextEngine' => 'PhabricatorFulltextEngine', 'PhabricatorRepositoryGitCommitChangeParserWorker' => 'PhabricatorRepositoryCommitChangeParserWorker', 'PhabricatorRepositoryGitCommitMessageParserWorker' => 'PhabricatorRepositoryCommitMessageParserWorker', 'PhabricatorRepositoryGitLFSRef' => array( diff --git a/src/applications/repository/search/PhabricatorRepositoryFulltextEngine.php b/src/applications/repository/search/PhabricatorRepositoryFulltextEngine.php new file mode 100644 index 0000000000..f666af552f --- /dev/null +++ b/src/applications/repository/search/PhabricatorRepositoryFulltextEngine.php @@ -0,0 +1,27 @@ +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()); + } + +} diff --git a/src/applications/repository/storage/PhabricatorRepository.php b/src/applications/repository/storage/PhabricatorRepository.php index 1a42eb8bd2..fd7413c392 100644 --- a/src/applications/repository/storage/PhabricatorRepository.php +++ b/src/applications/repository/storage/PhabricatorRepository.php @@ -14,7 +14,8 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO PhabricatorDestructibleInterface, PhabricatorProjectInterface, PhabricatorSpacesInterface, - PhabricatorConduitResultInterface { + PhabricatorConduitResultInterface, + PhabricatorFulltextInterface { /** * Shortest hash we'll recognize in raw "a829f32" form. @@ -2572,4 +2573,11 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO ); } +/* -( PhabricatorFulltextInterface )--------------------------------------- */ + + + public function newFulltextEngine() { + return new PhabricatorRepositoryFulltextEngine(); + } + } diff --git a/src/applications/search/management/PhabricatorSearchManagementIndexWorkflow.php b/src/applications/search/management/PhabricatorSearchManagementIndexWorkflow.php index 36996861a9..7838808f48 100644 --- a/src/applications/search/management/PhabricatorSearchManagementIndexWorkflow.php +++ b/src/applications/search/management/PhabricatorSearchManagementIndexWorkflow.php @@ -158,9 +158,15 @@ final class PhabricatorSearchManagementIndexWorkflow $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; + } }