diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 8e5a404477..499d0f108d 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -481,6 +481,7 @@ phutil_register_library_map(array( 'PhabricatorSearchDocumentRelationship' => 'applications/search/storage/document/relationship', 'PhabricatorSearchExecutor' => 'applications/search/execute/base', 'PhabricatorSearchField' => 'applications/search/constants/field', + 'PhabricatorSearchIndexController' => 'applications/search/controller/index', 'PhabricatorSearchManiphestIndexer' => 'applications/search/index/indexer/maniphest', 'PhabricatorSearchMySQLExecutor' => 'applications/search/execute/mysql', 'PhabricatorSearchQuery' => 'applications/search/storage/query', @@ -935,6 +936,7 @@ phutil_register_library_map(array( 'PhabricatorSearchDocument' => 'PhabricatorSearchDAO', 'PhabricatorSearchDocumentField' => 'PhabricatorSearchDAO', 'PhabricatorSearchDocumentRelationship' => 'PhabricatorSearchDAO', + 'PhabricatorSearchIndexController' => 'PhabricatorSearchBaseController', 'PhabricatorSearchManiphestIndexer' => 'PhabricatorSearchDocumentIndexer', 'PhabricatorSearchMySQLExecutor' => 'PhabricatorSearchExecutor', 'PhabricatorSearchQuery' => 'PhabricatorSearchDAO', diff --git a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php index 1a6611d623..cfae0b58db 100644 --- a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php +++ b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php @@ -192,6 +192,7 @@ class AphrontDefaultApplicationConfiguration => 'PhabricatorSearchAttachController', 'select/(?P\w+)/$' => 'PhabricatorSearchSelectController', + 'index/(?P[^/]+)/$' => 'PhabricatorSearchIndexController', ), '/project/' => array( diff --git a/src/applications/differential/editor/comment/DifferentialCommentEditor.php b/src/applications/differential/editor/comment/DifferentialCommentEditor.php index 03a919f96b..ab84984024 100644 --- a/src/applications/differential/editor/comment/DifferentialCommentEditor.php +++ b/src/applications/differential/editor/comment/DifferentialCommentEditor.php @@ -332,6 +332,9 @@ class DifferentialCommentEditor { id(new PhabricatorTimelineEvent('difx', $event_data)) ->recordEvent(); + // TODO: Move to a daemon? + PhabricatorSearchDifferentialIndexer::indexRevision($revision); + return $comment; } diff --git a/src/applications/differential/editor/comment/__init__.php b/src/applications/differential/editor/comment/__init__.php index ef928ffd41..a11be0084c 100644 --- a/src/applications/differential/editor/comment/__init__.php +++ b/src/applications/differential/editor/comment/__init__.php @@ -15,6 +15,7 @@ phutil_require_module('phabricator', 'applications/differential/storage/comment' phutil_require_module('phabricator', 'applications/differential/storage/inlinecomment'); phutil_require_module('phabricator', 'applications/herald/storage/transcript/base'); phutil_require_module('phabricator', 'applications/phid/handle/data'); +phutil_require_module('phabricator', 'applications/search/index/indexer/differential'); phutil_require_module('phabricator', 'infrastructure/daemon/timeline/storage/event'); phutil_require_module('phutil', 'utils'); diff --git a/src/applications/herald/controller/base/__init__.php b/src/applications/herald/controller/base/__init__.php index 953582f57f..d6e0098e21 100644 --- a/src/applications/herald/controller/base/__init__.php +++ b/src/applications/herald/controller/base/__init__.php @@ -8,6 +8,7 @@ phutil_require_module('phabricator', 'aphront/response/webpage'); phutil_require_module('phabricator', 'applications/base/controller/base'); +phutil_require_module('phabricator', 'infrastructure/env'); phutil_require_module('phutil', 'utils'); diff --git a/src/applications/search/controller/index/PhabricatorSearchIndexController.php b/src/applications/search/controller/index/PhabricatorSearchIndexController.php new file mode 100644 index 0000000000..b893b3c0dc --- /dev/null +++ b/src/applications/search/controller/index/PhabricatorSearchIndexController.php @@ -0,0 +1,141 @@ +phid = $data['phid']; + } + + public function processRequest() { + + $executor = new PhabricatorSearchMySQLExecutor(); + $document = $executor->reconstructDocument($this->phid); + if (!$document) { + return new Aphront404Response(); + } + + $panels = array(); + + $panel = new AphrontPanelView(); + $panel->setHeader('Abstract Document Index'); + + $props = array( + 'PHID' => phutil_escape_html($document->getPHID()), + 'Title' => phutil_escape_html($document->getDocumentTitle()), + 'Type' => phutil_escape_html($document->getDocumentType()), + ); + $rows = array(); + foreach ($props as $name => $value) { + $rows[] = array($name, $value); + } + $table = new AphrontTableView($rows); + $table->setColumnClasses( + array( + 'header', + '', + )); + $panel->appendChild($table); + $panels[] = $panel; + + + $panel = new AphrontPanelView(); + $panel->setHeader('Document Fields'); + + $fields = $document->getFieldData(); + $rows = array(); + foreach ($fields as $field) { + list($name, $corpus, $aux_phid) = $field; + $rows[] = array( + phutil_escape_html($name), + phutil_escape_html(nonempty($aux_phid, null)), + str_replace("\n", '
', phutil_escape_html($corpus)), + ); + } + + $table = new AphrontTableView($rows); + $table->setHeaders( + array( + 'Field', + 'Aux PHID', + 'Corpus', + )); + $table->setColumnClasses( + array( + '', + '', + 'wide', + )); + $panel->appendChild($table); + $panels[] = $panel; + + + $panel = new AphrontPanelView(); + $panel->setHeader('Document Relationships'); + + $relationships = $document->getRelationshipData(); + + $phids = ipull($relationships, 1); + $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); + + $rows = array(); + foreach ($relationships as $relationship) { + list($type, $phid, $rtype, $time) = $relationship; + $rows[] = array( + phutil_escape_html($type), + phutil_escape_html($phid), + phutil_escape_html($rtype), + $handles[$phid]->renderLink(), + ); + } + + $table = new AphrontTableView($rows); + $table->setHeaders( + array( + 'Relationship', + 'Related PHID', + 'Related Type', + 'Related Handle', + )); + $table->setColumnClasses( + array( + '', + '', + '', + 'wide', + )); + $panel->appendChild($table); + $panels[] = $panel; + + + return $this->buildStandardPageResponse( + $panels, + array( + 'title' => 'Raw Index', + )); + } + +} diff --git a/src/applications/search/controller/index/__init__.php b/src/applications/search/controller/index/__init__.php new file mode 100644 index 0000000000..6bb8ec7554 --- /dev/null +++ b/src/applications/search/controller/index/__init__.php @@ -0,0 +1,20 @@ +getTableName(); + $t_field = $dao_field->getTableName(); + $t_relationship = $dao_relationship->getTableName(); + + $doc = queryfx_one( + $dao_doc->establishConnection('r'), + 'SELECT * FROM %T WHERE phid = %s', + $t_doc, + $phid); + + if (!$doc) { + return null; + } + + $fields = queryfx_all( + $dao_field->establishConnection('r'), + 'SELECT * FROM %T WHERE phid = %s', + $t_field, + $phid); + + $relationships = queryfx_all( + $dao_relationship->establishConnection('r'), + 'SELECT * FROM %T WHERE phid = %s', + $t_relationship, + $phid); + + $adoc = id(new PhabricatorSearchAbstractDocument()) + ->setPHID($phid) + ->setDocumentType($doc['documentType']) + ->setDocumentTitle($doc['documentTitle']) + ->setDocumentCreated($doc['documentCreated']) + ->setDocumentModified($doc['documentModified']); + + foreach ($fields as $field) { + $adoc->addField( + $field['field'], + $field['corpus'], + $field['auxPHID']); + } + + foreach ($relationships as $relationship) { + $adoc->addRelationship( + $relationship['relation'], + $relationship['relatedPHID'], + $relationship['relatedType'], + $relationship['relatedTime']); + } + + return $adoc; + } + public function executeSearch(PhabricatorSearchQuery $query) { $where = array(); diff --git a/src/applications/search/execute/mysql/__init__.php b/src/applications/search/execute/mysql/__init__.php index b78985af0c..24a7ac6fcc 100644 --- a/src/applications/search/execute/mysql/__init__.php +++ b/src/applications/search/execute/mysql/__init__.php @@ -8,6 +8,7 @@ phutil_require_module('phabricator', 'applications/search/constants/relationship'); phutil_require_module('phabricator', 'applications/search/execute/base'); +phutil_require_module('phabricator', 'applications/search/index/abstractdocument'); phutil_require_module('phabricator', 'applications/search/storage/document/document'); phutil_require_module('phabricator', 'applications/search/storage/document/field'); phutil_require_module('phabricator', 'applications/search/storage/document/relationship'); diff --git a/src/applications/search/index/indexer/differential/PhabricatorSearchDifferentialIndexer.php b/src/applications/search/index/indexer/differential/PhabricatorSearchDifferentialIndexer.php index e22f7308cb..7055ab9652 100644 --- a/src/applications/search/index/indexer/differential/PhabricatorSearchDifferentialIndexer.php +++ b/src/applications/search/index/indexer/differential/PhabricatorSearchDifferentialIndexer.php @@ -77,12 +77,22 @@ class PhabricatorSearchDifferentialIndexer $rev->loadRelationships(); - foreach ($rev->getReviewers() as $phid) { + // If a revision needs review, the owners are the reviewers. Otherwise, the + // owner is the author (e.g., accepted, rejected, committed). + if ($rev->getStatus() == DifferentialRevisionStatus::NEEDS_REVIEW) { + foreach ($rev->getReviewers() as $phid) { + $doc->addRelationship( + PhabricatorSearchRelationship::RELATIONSHIP_OWNER, + $phid, + PhabricatorPHIDConstants::PHID_TYPE_USER, + $rev->getDateModified()); // Bogus timestamp. + } + } else { $doc->addRelationship( PhabricatorSearchRelationship::RELATIONSHIP_OWNER, - $phid, + $rev->getAuthorPHID(), PhabricatorPHIDConstants::PHID_TYPE_USER, - $rev->getDateModified()); // Bogus timestamp. + $rev->getDateCreated()); } $ccphids = $rev->getCCPHIDs();