mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-11 15:21:03 +01:00
Restore search indexing to Ponder questions
Summary: Ref T3578. Get indexing back, and try to simplify it a bit. Test Plan: Rebuilt QUES and MOCK indexes with `bin/search`. Created question with unique string, verified it appeared as a result. Added an answer with a unique string, got it as a result too. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T3578 Differential Revision: https://secure.phabricator.com/D6619
This commit is contained in:
parent
4c4fcb0bd1
commit
4308a932c2
4 changed files with 104 additions and 49 deletions
|
@ -12,12 +12,10 @@ final class PholioSearchIndexer extends PhabricatorSearchDocumentIndexer {
|
|||
protected function buildAbstractDocumentByPHID($phid) {
|
||||
$mock = $this->loadDocumentByPHID($phid);
|
||||
|
||||
$doc = new PhabricatorSearchAbstractDocument();
|
||||
$doc->setPHID($mock->getPHID());
|
||||
$doc->setDocumentType(phid_get_type($mock->getPHID()));
|
||||
$doc->setDocumentTitle($mock->getName());
|
||||
$doc->setDocumentCreated($mock->getDateCreated());
|
||||
$doc->setDocumentModified($mock->getDateModified());
|
||||
$doc = $this->newDocument($phid)
|
||||
->setDocumentTitle($mock->getName())
|
||||
->setDocumentCreated($mock->getDateCreated())
|
||||
->setDocumentModified($mock->getDateModified());
|
||||
|
||||
$doc->addField(
|
||||
PhabricatorSearchField::FIELD_BODY,
|
||||
|
@ -29,6 +27,11 @@ final class PholioSearchIndexer extends PhabricatorSearchDocumentIndexer {
|
|||
PhabricatorPeoplePHIDTypeUser::TYPECONST,
|
||||
$mock->getDateCreated());
|
||||
|
||||
$this->indexTransactions(
|
||||
$doc,
|
||||
new PholioTransactionQuery(),
|
||||
array($phid));
|
||||
|
||||
return $doc;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -153,6 +153,22 @@ final class PonderQuestionEditor
|
|||
return array($object->getAuthorPHID());
|
||||
}
|
||||
|
||||
protected function supportsSearch() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function shouldImplyCC(
|
||||
PhabricatorLiskDAO $object,
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case PonderQuestionTransaction::TYPE_ANSWERS:
|
||||
return true;
|
||||
}
|
||||
|
||||
return parent::shouldImplyCC($object, $xaction);
|
||||
}
|
||||
|
||||
// TODO: Mail support
|
||||
|
||||
}
|
||||
|
|
|
@ -10,14 +10,10 @@ final class PonderSearchIndexer
|
|||
protected function buildAbstractDocumentByPHID($phid) {
|
||||
$question = $this->loadDocumentByPHID($phid);
|
||||
|
||||
$question->attachRelated();
|
||||
|
||||
$doc = new PhabricatorSearchAbstractDocument();
|
||||
$doc->setPHID($question->getPHID());
|
||||
$doc->setDocumentType(PonderPHIDTypeQuestion::TYPECONST);
|
||||
$doc->setDocumentTitle($question->getTitle());
|
||||
$doc->setDocumentCreated($question->getDateCreated());
|
||||
$doc->setDocumentModified($question->getDateModified());
|
||||
$doc = $this->newDocument($phid)
|
||||
->setDocumentTitle($question->getTitle())
|
||||
->setDocumentCreated($question->getDateCreated())
|
||||
->setDocumentModified($question->getDateModified());
|
||||
|
||||
$doc->addField(
|
||||
PhabricatorSearchField::FIELD_BODY,
|
||||
|
@ -29,42 +25,28 @@ final class PonderSearchIndexer
|
|||
PhabricatorPeoplePHIDTypeUser::TYPECONST,
|
||||
$question->getDateCreated());
|
||||
|
||||
$comments = $question->getComments();
|
||||
foreach ($comments as $curcomment) {
|
||||
$doc->addField(
|
||||
PhabricatorSearchField::FIELD_COMMENT,
|
||||
$curcomment->getContent());
|
||||
}
|
||||
|
||||
$answers = $question->getAnswers();
|
||||
foreach ($answers as $curanswer) {
|
||||
if (strlen($curanswer->getContent())) {
|
||||
$doc->addField(
|
||||
PhabricatorSearchField::FIELD_COMMENT,
|
||||
$curanswer->getContent());
|
||||
}
|
||||
|
||||
$answer_comments = $curanswer->getComments();
|
||||
foreach ($answer_comments as $curcomment) {
|
||||
$answers = id(new PonderAnswerQuery())
|
||||
->setViewer($this->getViewer())
|
||||
->withQuestionIDs(array($question->getID()))
|
||||
->execute();
|
||||
foreach ($answers as $answer) {
|
||||
if (strlen($answer->getContent())) {
|
||||
$doc->addField(
|
||||
PhabricatorSearchField::FIELD_COMMENT,
|
||||
$curcomment->getContent());
|
||||
$answer->getContent());
|
||||
}
|
||||
}
|
||||
|
||||
$subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID(
|
||||
$question->getPHID());
|
||||
$handles = id(new PhabricatorObjectHandleData($subscribers))
|
||||
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||
->loadHandles();
|
||||
$this->indexTransactions(
|
||||
$doc,
|
||||
new PonderQuestionTransactionQuery(),
|
||||
array($phid));
|
||||
$this->indexTransactions(
|
||||
$doc,
|
||||
new PonderAnswerTransactionQuery(),
|
||||
mpull($answers, 'getPHID'));
|
||||
|
||||
foreach ($handles as $phid => $handle) {
|
||||
$doc->addRelationship(
|
||||
PhabricatorSearchRelationship::RELATIONSHIP_SUBSCRIBER,
|
||||
$phid,
|
||||
$handle->getType(),
|
||||
$question->getDateModified()); // Bogus timestamp.
|
||||
}
|
||||
$this->indexSubscribers($doc);
|
||||
|
||||
return $doc;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,10 @@ abstract class PhabricatorSearchDocumentIndexer {
|
|||
abstract public function getIndexableObject();
|
||||
abstract protected function buildAbstractDocumentByPHID($phid);
|
||||
|
||||
protected function getViewer() {
|
||||
return PhabricatorUser::getOmnipotentUser();
|
||||
}
|
||||
|
||||
public function shouldIndexDocumentByPHID($phid) {
|
||||
$object = $this->getIndexableObject();
|
||||
return (phid_get_type($phid) == phid_get_type($object->generatePHID()));
|
||||
|
@ -19,12 +23,14 @@ abstract class PhabricatorSearchDocumentIndexer {
|
|||
}
|
||||
|
||||
protected function loadDocumentByPHID($phid) {
|
||||
$object = $this->getIndexableObject();
|
||||
$document = $object->loadOneWhere('phid = %s', $phid);
|
||||
if (!$document) {
|
||||
throw new Exception("Unable to load document by phid '{$phid}'!");
|
||||
$object = id(new PhabricatorObjectQuery())
|
||||
->setViewer($this->getViewer())
|
||||
->withPHIDs(array($phid))
|
||||
->executeOne();
|
||||
if (!$object) {
|
||||
throw new Exception("Unable to load object by phid '{$phid}'!");
|
||||
}
|
||||
return $document;
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function indexDocumentByPHID($phid) {
|
||||
|
@ -51,4 +57,52 @@ abstract class PhabricatorSearchDocumentIndexer {
|
|||
return $this;
|
||||
}
|
||||
|
||||
protected function newDocument($phid) {
|
||||
return id(new PhabricatorSearchAbstractDocument())
|
||||
->setPHID($phid)
|
||||
->setDocumentType(phid_get_type($phid));
|
||||
}
|
||||
|
||||
protected function indexSubscribers(
|
||||
PhabricatorSearchAbstractDocument $doc) {
|
||||
|
||||
$subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID(
|
||||
$doc->getPHID());
|
||||
$handles = id(new PhabricatorHandleQuery())
|
||||
->setViewer($this->getViewer())
|
||||
->withPHIDs($subscribers)
|
||||
->execute();
|
||||
|
||||
foreach ($handles as $phid => $handle) {
|
||||
$doc->addRelationship(
|
||||
PhabricatorSearchRelationship::RELATIONSHIP_SUBSCRIBER,
|
||||
$phid,
|
||||
$handle->getType(),
|
||||
$doc->getDocumentModified()); // Bogus timestamp.
|
||||
}
|
||||
}
|
||||
|
||||
protected function indexTransactions(
|
||||
PhabricatorSearchAbstractDocument $doc,
|
||||
PhabricatorApplicationTransactionQuery $query,
|
||||
array $phids) {
|
||||
|
||||
$xactions = id(clone $query)
|
||||
->setViewer($this->getViewer())
|
||||
->withObjectPHIDs($phids)
|
||||
->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT))
|
||||
->execute();
|
||||
|
||||
foreach ($xactions as $xaction) {
|
||||
if (!$xaction->hasComment()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$comment = $xaction->getComment();
|
||||
$doc->addField(
|
||||
PhabricatorSearchField::FIELD_COMMENT,
|
||||
$comment->getContent());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue