1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

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
This commit is contained in:
epriestley 2018-02-15 17:02:23 -08:00
parent 143350fdba
commit 45403b162a
4 changed files with 75 additions and 7 deletions

View file

@ -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',

View file

@ -0,0 +1,31 @@
<?php
final class PhrictionContentSearchEngineAttachment
extends PhabricatorSearchEngineAttachment {
public function getAttachmentName() {
return pht('Document Content');
}
public function getAttachmentDescription() {
return pht('Get the content of documents or document histories.');
}
public function getAttachmentForObject($object, $data, $spec) {
if ($object instanceof PhrictionDocument) {
$content = $object->getContent();
} else {
$content = $object;
}
return array(
'title' => $content->getTitle(),
'path' => $content->getSlug(),
'authorPHID' => $content->getAuthorPHID(),
'content' => array(
'raw' => $content->getContent(),
),
);
}
}

View file

@ -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'),
);
}
}

View file

@ -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<string, wild>')
->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'),
);
}
}