From 45403b162aa52fad1eb739bcb409e58a432207ad Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 15 Feb 2018 17:02:23 -0800 Subject: [PATCH] Flesh out "phriction.document.search" slightly and provide page text for content/documents Summary: Depends on D19100. Ref T13077. Adds a "content" attachment to get the actual page text. This works on both "phriction.document.search" and "phriction.content.search". Test Plan: Called both API methods with the attachment, saw proper text content returned. Maniphest Tasks: T13077 Differential Revision: https://secure.phabricator.com/D19103 --- src/__phutil_library_map__.php | 3 ++ ...PhrictionContentSearchEngineAttachment.php | 31 +++++++++++++++ .../phriction/storage/PhrictionContent.php | 10 ++--- .../phriction/storage/PhrictionDocument.php | 38 ++++++++++++++++++- 4 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 src/applications/phriction/engineextension/PhrictionContentSearchEngineAttachment.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 4c9d40d9bc..f04f930863 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -4849,6 +4849,7 @@ phutil_register_library_map(array( 'PhrictionContentQuery' => 'applications/phriction/query/PhrictionContentQuery.php', 'PhrictionContentSearchConduitAPIMethod' => 'applications/phriction/conduit/PhrictionContentSearchConduitAPIMethod.php', 'PhrictionContentSearchEngine' => 'applications/phriction/query/PhrictionContentSearchEngine.php', + 'PhrictionContentSearchEngineAttachment' => 'applications/phriction/engineextension/PhrictionContentSearchEngineAttachment.php', 'PhrictionController' => 'applications/phriction/controller/PhrictionController.php', 'PhrictionCreateConduitAPIMethod' => 'applications/phriction/conduit/PhrictionCreateConduitAPIMethod.php', 'PhrictionDAO' => 'applications/phriction/storage/PhrictionDAO.php', @@ -10768,6 +10769,7 @@ phutil_register_library_map(array( 'PhrictionContentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhrictionContentSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', 'PhrictionContentSearchEngine' => 'PhabricatorApplicationSearchEngine', + 'PhrictionContentSearchEngineAttachment' => 'PhabricatorSearchEngineAttachment', 'PhrictionController' => 'PhabricatorController', 'PhrictionCreateConduitAPIMethod' => 'PhrictionConduitAPIMethod', 'PhrictionDAO' => 'PhabricatorLiskDAO', @@ -10784,6 +10786,7 @@ phutil_register_library_map(array( 'PhabricatorFerretInterface', 'PhabricatorProjectInterface', 'PhabricatorApplicationTransactionInterface', + 'PhabricatorConduitResultInterface', ), 'PhrictionDocumentAuthorHeraldField' => 'PhrictionDocumentHeraldField', 'PhrictionDocumentContentHeraldField' => 'PhrictionDocumentHeraldField', diff --git a/src/applications/phriction/engineextension/PhrictionContentSearchEngineAttachment.php b/src/applications/phriction/engineextension/PhrictionContentSearchEngineAttachment.php new file mode 100644 index 0000000000..3321f23eb0 --- /dev/null +++ b/src/applications/phriction/engineextension/PhrictionContentSearchEngineAttachment.php @@ -0,0 +1,31 @@ +getContent(); + } else { + $content = $object; + } + + return array( + 'title' => $content->getTitle(), + 'path' => $content->getSlug(), + 'authorPHID' => $content->getAuthorPHID(), + 'content' => array( + 'raw' => $content->getContent(), + ), + ); + } + +} diff --git a/src/applications/phriction/storage/PhrictionContent.php b/src/applications/phriction/storage/PhrictionContent.php index dc6bf19faa..80fabcaddc 100644 --- a/src/applications/phriction/storage/PhrictionContent.php +++ b/src/applications/phriction/storage/PhrictionContent.php @@ -118,10 +118,6 @@ final class PhrictionContent ->setKey('version') ->setType('int') ->setDescription(pht('Content version.')), - id(new PhabricatorConduitSearchFieldSpecification()) - ->setKey('authorPHID') - ->setType('phid') - ->setDescription(pht('Author of this version of the content.')), ); } @@ -129,12 +125,14 @@ final class PhrictionContent return array( 'documentPHID' => $this->getDocument()->getPHID(), 'version' => (int)$this->getVersion(), - 'authorPHID' => $this->getAuthorPHID(), ); } public function getConduitSearchAttachments() { - return array(); + return array( + id(new PhrictionContentSearchEngineAttachment()) + ->setAttachmentKey('content'), + ); } } diff --git a/src/applications/phriction/storage/PhrictionDocument.php b/src/applications/phriction/storage/PhrictionDocument.php index 1942f16efe..58d7cbee4a 100644 --- a/src/applications/phriction/storage/PhrictionDocument.php +++ b/src/applications/phriction/storage/PhrictionDocument.php @@ -10,7 +10,8 @@ final class PhrictionDocument extends PhrictionDAO PhabricatorFulltextInterface, PhabricatorFerretInterface, PhabricatorProjectInterface, - PhabricatorApplicationTransactionInterface { + PhabricatorApplicationTransactionInterface, + PhabricatorConduitResultInterface { protected $slug; protected $depth; @@ -288,4 +289,39 @@ final class PhrictionDocument extends PhrictionDAO return new PhrictionDocumentFerretEngine(); } + +/* -( PhabricatorConduitResultInterface )---------------------------------- */ + + + public function getFieldSpecificationsForConduit() { + return array( + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('path') + ->setType('string') + ->setDescription(pht('The path to the document.')), + id(new PhabricatorConduitSearchFieldSpecification()) + ->setKey('status') + ->setType('map') + ->setDescription(pht('Status information about the document.')), + ); + } + + public function getFieldValuesForConduit() { + $status = array( + 'value' => $this->getStatus(), + 'name' => $this->getStatusDisplayName(), + ); + + return array( + 'path' => $this->getSlug(), + 'status' => $status, + ); + } + + public function getConduitSearchAttachments() { + return array( + id(new PhrictionContentSearchEngineAttachment()) + ->setAttachmentKey('content'), + ); + } } -- 2.51.2