@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+104 -49
+9 -6
src/applications/pholio/search/PholioSearchIndexer.php
··· 12 12 protected function buildAbstractDocumentByPHID($phid) { 13 13 $mock = $this->loadDocumentByPHID($phid); 14 14 15 - $doc = new PhabricatorSearchAbstractDocument(); 16 - $doc->setPHID($mock->getPHID()); 17 - $doc->setDocumentType(phid_get_type($mock->getPHID())); 18 - $doc->setDocumentTitle($mock->getName()); 19 - $doc->setDocumentCreated($mock->getDateCreated()); 20 - $doc->setDocumentModified($mock->getDateModified()); 15 + $doc = $this->newDocument($phid) 16 + ->setDocumentTitle($mock->getName()) 17 + ->setDocumentCreated($mock->getDateCreated()) 18 + ->setDocumentModified($mock->getDateModified()); 21 19 22 20 $doc->addField( 23 21 PhabricatorSearchField::FIELD_BODY, ··· 28 26 $mock->getAuthorPHID(), 29 27 PhabricatorPeoplePHIDTypeUser::TYPECONST, 30 28 $mock->getDateCreated()); 29 + 30 + $this->indexTransactions( 31 + $doc, 32 + new PholioTransactionQuery(), 33 + array($phid)); 31 34 32 35 return $doc; 33 36 }
+16
src/applications/ponder/editor/PonderQuestionEditor.php
··· 153 153 return array($object->getAuthorPHID()); 154 154 } 155 155 156 + protected function supportsSearch() { 157 + return true; 158 + } 159 + 160 + protected function shouldImplyCC( 161 + PhabricatorLiskDAO $object, 162 + PhabricatorApplicationTransaction $xaction) { 163 + 164 + switch ($xaction->getTransactionType()) { 165 + case PonderQuestionTransaction::TYPE_ANSWERS: 166 + return true; 167 + } 168 + 169 + return parent::shouldImplyCC($object, $xaction); 170 + } 171 + 156 172 // TODO: Mail support 157 173 158 174 }
+20 -38
src/applications/ponder/search/PonderSearchIndexer.php
··· 10 10 protected function buildAbstractDocumentByPHID($phid) { 11 11 $question = $this->loadDocumentByPHID($phid); 12 12 13 - $question->attachRelated(); 14 - 15 - $doc = new PhabricatorSearchAbstractDocument(); 16 - $doc->setPHID($question->getPHID()); 17 - $doc->setDocumentType(PonderPHIDTypeQuestion::TYPECONST); 18 - $doc->setDocumentTitle($question->getTitle()); 19 - $doc->setDocumentCreated($question->getDateCreated()); 20 - $doc->setDocumentModified($question->getDateModified()); 13 + $doc = $this->newDocument($phid) 14 + ->setDocumentTitle($question->getTitle()) 15 + ->setDocumentCreated($question->getDateCreated()) 16 + ->setDocumentModified($question->getDateModified()); 21 17 22 18 $doc->addField( 23 19 PhabricatorSearchField::FIELD_BODY, ··· 29 25 PhabricatorPeoplePHIDTypeUser::TYPECONST, 30 26 $question->getDateCreated()); 31 27 32 - $comments = $question->getComments(); 33 - foreach ($comments as $curcomment) { 34 - $doc->addField( 35 - PhabricatorSearchField::FIELD_COMMENT, 36 - $curcomment->getContent()); 37 - } 38 - 39 - $answers = $question->getAnswers(); 40 - foreach ($answers as $curanswer) { 41 - if (strlen($curanswer->getContent())) { 42 - $doc->addField( 43 - PhabricatorSearchField::FIELD_COMMENT, 44 - $curanswer->getContent()); 45 - } 46 - 47 - $answer_comments = $curanswer->getComments(); 48 - foreach ($answer_comments as $curcomment) { 28 + $answers = id(new PonderAnswerQuery()) 29 + ->setViewer($this->getViewer()) 30 + ->withQuestionIDs(array($question->getID())) 31 + ->execute(); 32 + foreach ($answers as $answer) { 33 + if (strlen($answer->getContent())) { 49 34 $doc->addField( 50 35 PhabricatorSearchField::FIELD_COMMENT, 51 - $curcomment->getContent()); 36 + $answer->getContent()); 52 37 } 53 38 } 54 39 55 - $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID( 56 - $question->getPHID()); 57 - $handles = id(new PhabricatorObjectHandleData($subscribers)) 58 - ->setViewer(PhabricatorUser::getOmnipotentUser()) 59 - ->loadHandles(); 40 + $this->indexTransactions( 41 + $doc, 42 + new PonderQuestionTransactionQuery(), 43 + array($phid)); 44 + $this->indexTransactions( 45 + $doc, 46 + new PonderAnswerTransactionQuery(), 47 + mpull($answers, 'getPHID')); 60 48 61 - foreach ($handles as $phid => $handle) { 62 - $doc->addRelationship( 63 - PhabricatorSearchRelationship::RELATIONSHIP_SUBSCRIBER, 64 - $phid, 65 - $handle->getType(), 66 - $question->getDateModified()); // Bogus timestamp. 67 - } 49 + $this->indexSubscribers($doc); 68 50 69 51 return $doc; 70 52 }
+59 -5
src/applications/search/index/PhabricatorSearchDocumentIndexer.php
··· 8 8 abstract public function getIndexableObject(); 9 9 abstract protected function buildAbstractDocumentByPHID($phid); 10 10 11 + protected function getViewer() { 12 + return PhabricatorUser::getOmnipotentUser(); 13 + } 14 + 11 15 public function shouldIndexDocumentByPHID($phid) { 12 16 $object = $this->getIndexableObject(); 13 17 return (phid_get_type($phid) == phid_get_type($object->generatePHID())); ··· 19 23 } 20 24 21 25 protected function loadDocumentByPHID($phid) { 22 - $object = $this->getIndexableObject(); 23 - $document = $object->loadOneWhere('phid = %s', $phid); 24 - if (!$document) { 25 - throw new Exception("Unable to load document by phid '{$phid}'!"); 26 + $object = id(new PhabricatorObjectQuery()) 27 + ->setViewer($this->getViewer()) 28 + ->withPHIDs(array($phid)) 29 + ->executeOne(); 30 + if (!$object) { 31 + throw new Exception("Unable to load object by phid '{$phid}'!"); 26 32 } 27 - return $document; 33 + return $object; 28 34 } 29 35 30 36 public function indexDocumentByPHID($phid) { ··· 49 55 } 50 56 51 57 return $this; 58 + } 59 + 60 + protected function newDocument($phid) { 61 + return id(new PhabricatorSearchAbstractDocument()) 62 + ->setPHID($phid) 63 + ->setDocumentType(phid_get_type($phid)); 64 + } 65 + 66 + protected function indexSubscribers( 67 + PhabricatorSearchAbstractDocument $doc) { 68 + 69 + $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID( 70 + $doc->getPHID()); 71 + $handles = id(new PhabricatorHandleQuery()) 72 + ->setViewer($this->getViewer()) 73 + ->withPHIDs($subscribers) 74 + ->execute(); 75 + 76 + foreach ($handles as $phid => $handle) { 77 + $doc->addRelationship( 78 + PhabricatorSearchRelationship::RELATIONSHIP_SUBSCRIBER, 79 + $phid, 80 + $handle->getType(), 81 + $doc->getDocumentModified()); // Bogus timestamp. 82 + } 83 + } 84 + 85 + protected function indexTransactions( 86 + PhabricatorSearchAbstractDocument $doc, 87 + PhabricatorApplicationTransactionQuery $query, 88 + array $phids) { 89 + 90 + $xactions = id(clone $query) 91 + ->setViewer($this->getViewer()) 92 + ->withObjectPHIDs($phids) 93 + ->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT)) 94 + ->execute(); 95 + 96 + foreach ($xactions as $xaction) { 97 + if (!$xaction->hasComment()) { 98 + continue; 99 + } 100 + 101 + $comment = $xaction->getComment(); 102 + $doc->addField( 103 + PhabricatorSearchField::FIELD_COMMENT, 104 + $comment->getContent()); 105 + } 52 106 } 53 107 54 108 }