mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-25 22:18:19 +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) {
|
protected function buildAbstractDocumentByPHID($phid) {
|
||||||
$mock = $this->loadDocumentByPHID($phid);
|
$mock = $this->loadDocumentByPHID($phid);
|
||||||
|
|
||||||
$doc = new PhabricatorSearchAbstractDocument();
|
$doc = $this->newDocument($phid)
|
||||||
$doc->setPHID($mock->getPHID());
|
->setDocumentTitle($mock->getName())
|
||||||
$doc->setDocumentType(phid_get_type($mock->getPHID()));
|
->setDocumentCreated($mock->getDateCreated())
|
||||||
$doc->setDocumentTitle($mock->getName());
|
->setDocumentModified($mock->getDateModified());
|
||||||
$doc->setDocumentCreated($mock->getDateCreated());
|
|
||||||
$doc->setDocumentModified($mock->getDateModified());
|
|
||||||
|
|
||||||
$doc->addField(
|
$doc->addField(
|
||||||
PhabricatorSearchField::FIELD_BODY,
|
PhabricatorSearchField::FIELD_BODY,
|
||||||
|
@ -29,6 +27,11 @@ final class PholioSearchIndexer extends PhabricatorSearchDocumentIndexer {
|
||||||
PhabricatorPeoplePHIDTypeUser::TYPECONST,
|
PhabricatorPeoplePHIDTypeUser::TYPECONST,
|
||||||
$mock->getDateCreated());
|
$mock->getDateCreated());
|
||||||
|
|
||||||
|
$this->indexTransactions(
|
||||||
|
$doc,
|
||||||
|
new PholioTransactionQuery(),
|
||||||
|
array($phid));
|
||||||
|
|
||||||
return $doc;
|
return $doc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,6 +153,22 @@ final class PonderQuestionEditor
|
||||||
return array($object->getAuthorPHID());
|
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
|
// TODO: Mail support
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,14 +10,10 @@ final class PonderSearchIndexer
|
||||||
protected function buildAbstractDocumentByPHID($phid) {
|
protected function buildAbstractDocumentByPHID($phid) {
|
||||||
$question = $this->loadDocumentByPHID($phid);
|
$question = $this->loadDocumentByPHID($phid);
|
||||||
|
|
||||||
$question->attachRelated();
|
$doc = $this->newDocument($phid)
|
||||||
|
->setDocumentTitle($question->getTitle())
|
||||||
$doc = new PhabricatorSearchAbstractDocument();
|
->setDocumentCreated($question->getDateCreated())
|
||||||
$doc->setPHID($question->getPHID());
|
->setDocumentModified($question->getDateModified());
|
||||||
$doc->setDocumentType(PonderPHIDTypeQuestion::TYPECONST);
|
|
||||||
$doc->setDocumentTitle($question->getTitle());
|
|
||||||
$doc->setDocumentCreated($question->getDateCreated());
|
|
||||||
$doc->setDocumentModified($question->getDateModified());
|
|
||||||
|
|
||||||
$doc->addField(
|
$doc->addField(
|
||||||
PhabricatorSearchField::FIELD_BODY,
|
PhabricatorSearchField::FIELD_BODY,
|
||||||
|
@ -29,42 +25,28 @@ final class PonderSearchIndexer
|
||||||
PhabricatorPeoplePHIDTypeUser::TYPECONST,
|
PhabricatorPeoplePHIDTypeUser::TYPECONST,
|
||||||
$question->getDateCreated());
|
$question->getDateCreated());
|
||||||
|
|
||||||
$comments = $question->getComments();
|
$answers = id(new PonderAnswerQuery())
|
||||||
foreach ($comments as $curcomment) {
|
->setViewer($this->getViewer())
|
||||||
$doc->addField(
|
->withQuestionIDs(array($question->getID()))
|
||||||
PhabricatorSearchField::FIELD_COMMENT,
|
->execute();
|
||||||
$curcomment->getContent());
|
foreach ($answers as $answer) {
|
||||||
}
|
if (strlen($answer->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) {
|
|
||||||
$doc->addField(
|
$doc->addField(
|
||||||
PhabricatorSearchField::FIELD_COMMENT,
|
PhabricatorSearchField::FIELD_COMMENT,
|
||||||
$curcomment->getContent());
|
$answer->getContent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID(
|
$this->indexTransactions(
|
||||||
$question->getPHID());
|
$doc,
|
||||||
$handles = id(new PhabricatorObjectHandleData($subscribers))
|
new PonderQuestionTransactionQuery(),
|
||||||
->setViewer(PhabricatorUser::getOmnipotentUser())
|
array($phid));
|
||||||
->loadHandles();
|
$this->indexTransactions(
|
||||||
|
$doc,
|
||||||
|
new PonderAnswerTransactionQuery(),
|
||||||
|
mpull($answers, 'getPHID'));
|
||||||
|
|
||||||
foreach ($handles as $phid => $handle) {
|
$this->indexSubscribers($doc);
|
||||||
$doc->addRelationship(
|
|
||||||
PhabricatorSearchRelationship::RELATIONSHIP_SUBSCRIBER,
|
|
||||||
$phid,
|
|
||||||
$handle->getType(),
|
|
||||||
$question->getDateModified()); // Bogus timestamp.
|
|
||||||
}
|
|
||||||
|
|
||||||
return $doc;
|
return $doc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,10 @@ abstract class PhabricatorSearchDocumentIndexer {
|
||||||
abstract public function getIndexableObject();
|
abstract public function getIndexableObject();
|
||||||
abstract protected function buildAbstractDocumentByPHID($phid);
|
abstract protected function buildAbstractDocumentByPHID($phid);
|
||||||
|
|
||||||
|
protected function getViewer() {
|
||||||
|
return PhabricatorUser::getOmnipotentUser();
|
||||||
|
}
|
||||||
|
|
||||||
public function shouldIndexDocumentByPHID($phid) {
|
public function shouldIndexDocumentByPHID($phid) {
|
||||||
$object = $this->getIndexableObject();
|
$object = $this->getIndexableObject();
|
||||||
return (phid_get_type($phid) == phid_get_type($object->generatePHID()));
|
return (phid_get_type($phid) == phid_get_type($object->generatePHID()));
|
||||||
|
@ -19,12 +23,14 @@ abstract class PhabricatorSearchDocumentIndexer {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function loadDocumentByPHID($phid) {
|
protected function loadDocumentByPHID($phid) {
|
||||||
$object = $this->getIndexableObject();
|
$object = id(new PhabricatorObjectQuery())
|
||||||
$document = $object->loadOneWhere('phid = %s', $phid);
|
->setViewer($this->getViewer())
|
||||||
if (!$document) {
|
->withPHIDs(array($phid))
|
||||||
throw new Exception("Unable to load document by phid '{$phid}'!");
|
->executeOne();
|
||||||
|
if (!$object) {
|
||||||
|
throw new Exception("Unable to load object by phid '{$phid}'!");
|
||||||
}
|
}
|
||||||
return $document;
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function indexDocumentByPHID($phid) {
|
public function indexDocumentByPHID($phid) {
|
||||||
|
@ -51,4 +57,52 @@ abstract class PhabricatorSearchDocumentIndexer {
|
||||||
return $this;
|
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…
Add table
Reference in a new issue