From b9d004e9c41b3d2f3e54d89bedfb0d31dc0eea59 Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Fri, 5 Jun 2015 07:27:48 +1000 Subject: [PATCH] Integrate Diviner with global search Summary: Fixes T7458. Integrates #diviner into #applicationsearch by indexing `DivinerLiveBook` and `DivinerLiveSymbol` search documents. Depends on D13157. Test Plan: Ran `./bin/search index --all --type BOOK` and `./bin/search index --all --type ATOM` and then searched for various symbols via global search. Reviewers: epriestley, #blessed_reviewers Subscribers: Korvin, epriestley Maniphest Tasks: T7458 Differential Revision: https://secure.phabricator.com/D13090 --- src/__phutil_library_map__.php | 5 +++ .../PhabricatorDivinerApplication.php | 7 +++++ .../diviner/phid/DivinerAtomPHIDType.php | 15 +++++++-- .../diviner/phid/DivinerBookPHIDType.php | 9 +++--- .../publisher/DivinerLivePublisher.php | 6 ++++ .../search/DivinerAtomSearchIndexer.php | 31 +++++++++++++++++++ .../search/DivinerBookSearchIndexer.php | 25 +++++++++++++++ .../diviner/storage/DivinerLiveBook.php | 3 +- .../PhabricatorSearchRelationship.php | 1 + 9 files changed, 93 insertions(+), 9 deletions(-) create mode 100644 src/applications/diviner/search/DivinerAtomSearchIndexer.php create mode 100644 src/applications/diviner/search/DivinerBookSearchIndexer.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index f04138b08d..c9672655e7 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -642,12 +642,14 @@ phutil_register_library_map(array( 'DivinerAtomQuery' => 'applications/diviner/query/DivinerAtomQuery.php', 'DivinerAtomRef' => 'applications/diviner/atom/DivinerAtomRef.php', 'DivinerAtomSearchEngine' => 'applications/diviner/query/DivinerAtomSearchEngine.php', + 'DivinerAtomSearchIndexer' => 'applications/diviner/search/DivinerAtomSearchIndexer.php', 'DivinerAtomizeWorkflow' => 'applications/diviner/workflow/DivinerAtomizeWorkflow.php', 'DivinerAtomizer' => 'applications/diviner/atomizer/DivinerAtomizer.php', 'DivinerBookController' => 'applications/diviner/controller/DivinerBookController.php', 'DivinerBookItemView' => 'applications/diviner/view/DivinerBookItemView.php', 'DivinerBookPHIDType' => 'applications/diviner/phid/DivinerBookPHIDType.php', 'DivinerBookQuery' => 'applications/diviner/query/DivinerBookQuery.php', + 'DivinerBookSearchIndexer' => 'applications/diviner/search/DivinerBookSearchIndexer.php', 'DivinerController' => 'applications/diviner/controller/DivinerController.php', 'DivinerDAO' => 'applications/diviner/storage/DivinerDAO.php', 'DivinerDefaultRenderer' => 'applications/diviner/renderer/DivinerDefaultRenderer.php', @@ -3884,11 +3886,13 @@ phutil_register_library_map(array( 'DivinerAtomPHIDType' => 'PhabricatorPHIDType', 'DivinerAtomQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'DivinerAtomSearchEngine' => 'PhabricatorApplicationSearchEngine', + 'DivinerAtomSearchIndexer' => 'PhabricatorSearchDocumentIndexer', 'DivinerAtomizeWorkflow' => 'DivinerWorkflow', 'DivinerBookController' => 'DivinerController', 'DivinerBookItemView' => 'AphrontTagView', 'DivinerBookPHIDType' => 'PhabricatorPHIDType', 'DivinerBookQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', + 'DivinerBookSearchIndexer' => 'PhabricatorSearchDocumentIndexer', 'DivinerController' => 'PhabricatorController', 'DivinerDAO' => 'PhabricatorLiskDAO', 'DivinerDefaultRenderer' => 'DivinerRenderer', @@ -3899,6 +3903,7 @@ phutil_register_library_map(array( 'DivinerLiveBook' => array( 'DivinerDAO', 'PhabricatorPolicyInterface', + 'PhabricatorProjectInterface', 'PhabricatorDestructibleInterface', ), 'DivinerLivePublisher' => 'DivinerPublisher', diff --git a/src/applications/diviner/application/PhabricatorDivinerApplication.php b/src/applications/diviner/application/PhabricatorDivinerApplication.php index 895545a1cf..68b569213a 100644 --- a/src/applications/diviner/application/PhabricatorDivinerApplication.php +++ b/src/applications/diviner/application/PhabricatorDivinerApplication.php @@ -58,4 +58,11 @@ final class PhabricatorDivinerApplication extends PhabricatorApplication { ); } + public function getApplicationSearchDocumentTypes() { + return array( + DivinerAtomPHIDType::TYPECONST, + DivinerBookPHIDType::TYPECONST, + ); + } + } diff --git a/src/applications/diviner/phid/DivinerAtomPHIDType.php b/src/applications/diviner/phid/DivinerAtomPHIDType.php index 21f0b105d3..308efedde5 100644 --- a/src/applications/diviner/phid/DivinerAtomPHIDType.php +++ b/src/applications/diviner/phid/DivinerAtomPHIDType.php @@ -5,7 +5,7 @@ final class DivinerAtomPHIDType extends PhabricatorPHIDType { const TYPECONST = 'ATOM'; public function getTypeName() { - return pht('Atom'); + return pht('Diviner Atom'); } public function newObject() { @@ -28,8 +28,17 @@ final class DivinerAtomPHIDType extends PhabricatorPHIDType { foreach ($handles as $phid => $handle) { $atom = $objects[$phid]; - $handle->setName($atom->getTitle()); - $handle->setURI($atom->getName()); + $book = $atom->getBook()->getName(); + $name = $atom->getName(); + $type = $atom->getType(); + + $handle + ->setName($atom->getName()) + ->setTitle($atom->getTitle()) + ->setURI("/book/{$book}/{$type}/{$name}/") + ->setStatus($atom->getGraphHash() + ? PhabricatorObjectHandle::STATUS_OPEN + : PhabricatorObjectHandle::STATUS_CLOSED); } } diff --git a/src/applications/diviner/phid/DivinerBookPHIDType.php b/src/applications/diviner/phid/DivinerBookPHIDType.php index 9828b3e981..7eda61a976 100644 --- a/src/applications/diviner/phid/DivinerBookPHIDType.php +++ b/src/applications/diviner/phid/DivinerBookPHIDType.php @@ -5,7 +5,7 @@ final class DivinerBookPHIDType extends PhabricatorPHIDType { const TYPECONST = 'BOOK'; public function getTypeName() { - return pht('Book'); + return pht('Diviner Book'); } public function newObject() { @@ -30,9 +30,10 @@ final class DivinerBookPHIDType extends PhabricatorPHIDType { $name = $book->getName(); - $handle->setName($book->getShortTitle()); - $handle->setFullName($book->getTitle()); - $handle->setURI("/diviner/book/{$name}/"); + $handle + ->setName($book->getShortTitle()) + ->setFullName($book->getTitle()) + ->setURI("/book/{$name}/"); } } diff --git a/src/applications/diviner/publisher/DivinerLivePublisher.php b/src/applications/diviner/publisher/DivinerLivePublisher.php index 25d1464b4e..1bad2dcb8e 100644 --- a/src/applications/diviner/publisher/DivinerLivePublisher.php +++ b/src/applications/diviner/publisher/DivinerLivePublisher.php @@ -18,6 +18,9 @@ final class DivinerLivePublisher extends DivinerPublisher { $book->setConfigurationData($this->getConfigurationData())->save(); $this->book = $book; + + id(new PhabricatorSearchIndexer()) + ->queueDocumentForIndexing($book->getPHID()); } return $this->book; @@ -122,6 +125,9 @@ final class DivinerLivePublisher extends DivinerPublisher { $symbol->save(); + id(new PhabricatorSearchIndexer()) + ->queueDocumentForIndexing($symbol->getPHID()); + // TODO: We probably need a finer-grained sense of what "documentable" // atoms are. Neither files nor methods are currently considered // documentable, but for different reasons: files appear nowhere, while diff --git a/src/applications/diviner/search/DivinerAtomSearchIndexer.php b/src/applications/diviner/search/DivinerAtomSearchIndexer.php new file mode 100644 index 0000000000..8927f35cd5 --- /dev/null +++ b/src/applications/diviner/search/DivinerAtomSearchIndexer.php @@ -0,0 +1,31 @@ +loadDocumentByPHID($phid); + $book = $atom->getBook(); + + $doc = $this->newDocument($phid) + ->setDocumentTitle($atom->getTitle()) + ->setDocumentCreated($book->getDateCreated()) + ->setDocumentModified($book->getDateModified()); + + $doc->addField( + PhabricatorSearchField::FIELD_BODY, + $atom->getSummary()); + + $doc->addRelationship( + PhabricatorSearchRelationship::RELATIONSHIP_BOOK, + $atom->getBookPHID(), + DivinerBookPHIDType::TYPECONST, + $book->getDateCreated()); + + return $doc; + } + +} diff --git a/src/applications/diviner/search/DivinerBookSearchIndexer.php b/src/applications/diviner/search/DivinerBookSearchIndexer.php new file mode 100644 index 0000000000..c17c627a06 --- /dev/null +++ b/src/applications/diviner/search/DivinerBookSearchIndexer.php @@ -0,0 +1,25 @@ +loadDocumentByPHID($phid); + + $doc = $this->newDocument($phid) + ->setDocumentTitle($book->getTitle()) + ->setDocumentCreated($book->getDateCreated()) + ->setDocumentModified($book->getDateModified()); + + $doc->addField( + PhabricatorSearchField::FIELD_BODY, + $book->getPreface()); + + return $doc; + } + + +} diff --git a/src/applications/diviner/storage/DivinerLiveBook.php b/src/applications/diviner/storage/DivinerLiveBook.php index 41e6ab5b21..ddb03e9d14 100644 --- a/src/applications/diviner/storage/DivinerLiveBook.php +++ b/src/applications/diviner/storage/DivinerLiveBook.php @@ -42,8 +42,7 @@ final class DivinerLiveBook extends DivinerDAO } public function generatePHID() { - return PhabricatorPHID::generateNewPHID( - DivinerBookPHIDType::TYPECONST); + return PhabricatorPHID::generateNewPHID(DivinerBookPHIDType::TYPECONST); } public function getTitle() { diff --git a/src/applications/search/constants/PhabricatorSearchRelationship.php b/src/applications/search/constants/PhabricatorSearchRelationship.php index cde5f6539d..8631aeec29 100644 --- a/src/applications/search/constants/PhabricatorSearchRelationship.php +++ b/src/applications/search/constants/PhabricatorSearchRelationship.php @@ -3,6 +3,7 @@ final class PhabricatorSearchRelationship { const RELATIONSHIP_AUTHOR = 'auth'; + const RELATIONSHIP_BOOK = 'book'; const RELATIONSHIP_REVIEWER = 'revw'; const RELATIONSHIP_SUBSCRIBER = 'subs'; const RELATIONSHIP_COMMENTER = 'comm';