Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13986283
D8346.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
12 KB
Referenced Files
None
Subscribers
None
D8346.diff
View Options
Index: src/applications/differential/customfield/DifferentialSummaryField.php
===================================================================
--- src/applications/differential/customfield/DifferentialSummaryField.php
+++ src/applications/differential/customfield/DifferentialSummaryField.php
@@ -78,4 +78,15 @@
$xaction->getNewValue());
}
+ public function shouldAppearInGlobalSearch() {
+ return true;
+ }
+
+ public function updateAbstractDocument(
+ PhabricatorSearchAbstractDocument $document) {
+ if (strlen($this->getValue())) {
+ $document->addField('body', $this->getValue());
+ }
+ }
+
}
Index: src/applications/differential/customfield/DifferentialTestPlanField.php
===================================================================
--- src/applications/differential/customfield/DifferentialTestPlanField.php
+++ src/applications/differential/customfield/DifferentialTestPlanField.php
@@ -92,4 +92,16 @@
$xaction->getNewValue());
}
+
+ public function shouldAppearInGlobalSearch() {
+ return true;
+ }
+
+ public function updateAbstractDocument(
+ PhabricatorSearchAbstractDocument $document) {
+ if (strlen($this->getValue())) {
+ $document->addField('plan', $this->getValue());
+ }
+ }
+
}
Index: src/applications/differential/search/DifferentialSearchIndexer.php
===================================================================
--- src/applications/differential/search/DifferentialSearchIndexer.php
+++ src/applications/differential/search/DifferentialSearchIndexer.php
@@ -1,8 +1,5 @@
<?php
-/**
- * @group differential
- */
final class DifferentialSearchIndexer
extends PhabricatorSearchDocumentIndexer {
@@ -10,6 +7,18 @@
return new DifferentialRevision();
}
+ protected function loadDocumentByPHID($phid) {
+ $object = id(new DifferentialRevisionQuery())
+ ->setViewer($this->getViewer())
+ ->withPHIDs(array($phid))
+ ->needReviewerStatus(true)
+ ->executeOne();
+ if (!$object) {
+ throw new Exception("Unable to load object by phid '{$phid}'!");
+ }
+ return $object;
+ }
+
protected function buildAbstractDocumentByPHID($phid) {
$rev = $this->loadDocumentByPHID($phid);
@@ -20,24 +29,6 @@
$doc->setDocumentCreated($rev->getDateCreated());
$doc->setDocumentModified($rev->getDateModified());
- $aux_fields = DifferentialFieldSelector::newSelector()
- ->getFieldSpecifications();
- foreach ($aux_fields as $key => $aux_field) {
- $aux_field->setUser(PhabricatorUser::getOmnipotentUser());
- if (!$aux_field->shouldAddToSearchIndex()) {
- unset($aux_fields[$key]);
- }
- }
-
- $aux_fields = DifferentialAuxiliaryField::loadFromStorage(
- $rev,
- $aux_fields);
- foreach ($aux_fields as $aux_field) {
- $doc->addField(
- $aux_field->getKeyForSearchIndex(),
- $aux_field->getValueForSearchIndex());
- }
-
$doc->addRelationship(
PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR,
$rev->getAuthorPHID(),
@@ -52,29 +43,16 @@
DifferentialPHIDTypeRevision::TYPECONST,
time());
- $comments = id(new DifferentialCommentQuery())
- ->withRevisionPHIDs(array($rev->getPHID()))
- ->execute();
-
- $inlines = id(new DifferentialInlineCommentQuery())
- ->withRevisionIDs(array($rev->getID()))
- ->withNotDraft(true)
- ->execute();
-
- foreach (array_merge($comments, $inlines) as $comment) {
- if (strlen($comment->getContent())) {
- $doc->addField(
- PhabricatorSearchField::FIELD_COMMENT,
- $comment->getContent());
- }
- }
-
- $rev->loadRelationships();
+ $this->indexTransactions(
+ $doc,
+ new DifferentialTransactionQuery(),
+ array($rev->getPHID()));
// If a revision needs review, the owners are the reviewers. Otherwise, the
// owner is the author (e.g., accepted, rejected, closed).
if ($rev->getStatus() == ArcanistDifferentialRevisionStatus::NEEDS_REVIEW) {
- $reviewers = $rev->getReviewers();
+ $reviewers = $rev->getReviewerStatus();
+ $reviewers = mpull($reviewers, 'getReviewerPHID', 'getReviewerPHID');
if ($reviewers) {
foreach ($reviewers as $phid) {
$doc->addRelationship(
@@ -98,20 +76,6 @@
$rev->getDateCreated());
}
- $ccphids = $rev->getCCPHIDs();
- $handles = id(new PhabricatorHandleQuery())
- ->setViewer(PhabricatorUser::getOmnipotentUser())
- ->withPHIDs($ccphids)
- ->execute();
-
- foreach ($handles as $phid => $handle) {
- $doc->addRelationship(
- PhabricatorSearchRelationship::RELATIONSHIP_SUBSCRIBER,
- $phid,
- $handle->getType(),
- $rev->getDateModified()); // Bogus timestamp.
- }
-
return $doc;
}
}
Index: src/applications/maniphest/search/ManiphestSearchIndexer.php
===================================================================
--- src/applications/maniphest/search/ManiphestSearchIndexer.php
+++ src/applications/maniphest/search/ManiphestSearchIndexer.php
@@ -81,8 +81,6 @@
time());
}
- $this->indexCustomFields($doc, $task);
-
return $doc;
}
}
Index: src/applications/people/search/PhabricatorUserSearchIndexer.php
===================================================================
--- src/applications/people/search/PhabricatorUserSearchIndexer.php
+++ src/applications/people/search/PhabricatorUserSearchIndexer.php
@@ -25,8 +25,6 @@
PhabricatorPeoplePHIDTypeUser::TYPECONST,
time());
- $this->indexCustomFields($doc, $user);
-
return $doc;
}
}
Index: src/applications/ponder/search/PonderSearchIndexer.php
===================================================================
--- src/applications/ponder/search/PonderSearchIndexer.php
+++ src/applications/ponder/search/PonderSearchIndexer.php
@@ -46,8 +46,6 @@
new PonderAnswerTransactionQuery(),
mpull($answers, 'getPHID'));
- $this->indexSubscribers($doc);
-
return $doc;
}
}
Index: src/applications/project/search/PhabricatorProjectSearchIndexer.php
===================================================================
--- src/applications/project/search/PhabricatorProjectSearchIndexer.php
+++ src/applications/project/search/PhabricatorProjectSearchIndexer.php
@@ -17,9 +17,6 @@
$doc->setDocumentCreated($project->getDateCreated());
$doc->setDocumentModified($project->getDateModified());
- $this->indexSubscribers($doc);
- $this->indexCustomFields($doc, $project);
-
$doc->addRelationship(
$project->isArchived()
? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED
Index: src/applications/search/index/PhabricatorSearchDocumentIndexer.php
===================================================================
--- src/applications/search/index/PhabricatorSearchDocumentIndexer.php
+++ src/applications/search/index/PhabricatorSearchDocumentIndexer.php
@@ -37,6 +37,19 @@
try {
$document = $this->buildAbstractDocumentByPHID($phid);
+ $object = $this->loadDocumentByPHID($phid);
+
+ // Automatically rebuild CustomField indexes if the object uses custom
+ // fields.
+ if ($object instanceof PhabricatorCustomFieldInterface) {
+ $this->indexCustomFields($document, $object);
+ }
+
+ // Automatically rebuild subscriber indexes if the object is subscribable.
+ if ($object instanceof PhabricatorSubscribableInterface) {
+ $this->indexSubscribers($document);
+ }
+
$engine = PhabricatorSearchEngineSelector::newSelector()->newEngine();
try {
$engine->reindexAbstractDocument($document);
@@ -107,7 +120,7 @@
}
protected function indexCustomFields(
- PhabricatorSearchAbstractDocument $doc,
+ PhabricatorSearchAbstractDocument $document,
PhabricatorCustomFieldInterface $object) {
// Rebuild the ApplicationSearch indexes. These are internal and not part of
@@ -116,17 +129,16 @@
$field_list = PhabricatorCustomField::getObjectFields(
$object,
- PhabricatorCustomField::ROLE_APPLICATIONSEARCH);
+ PhabricatorCustomField::ROLE_DEFAULT);
$field_list->setViewer($this->getViewer());
$field_list->readFieldsFromStorage($object);
+
+ // Rebuild ApplicationSearch indexes.
$field_list->rebuildIndexes($object);
- // We could also allow fields to provide fulltext content, and index it
- // here on the document. No one has asked for this yet, though, and the
- // existing "search" key isn't a good fit to interpret to mean we should
- // index stuff here, since it can be set on a lot of fields which don't
- // contain anything resembling fulltext.
+ // Rebuild global search indexes.
+ $field_list->updateAbstractDocument($document);
}
private function dispatchDidUpdateIndexEvent(
Index: src/infrastructure/customfield/field/PhabricatorCustomField.php
===================================================================
--- src/infrastructure/customfield/field/PhabricatorCustomField.php
+++ src/infrastructure/customfield/field/PhabricatorCustomField.php
@@ -1,16 +1,17 @@
<?php
/**
- * @task apps Building Applications with Custom Fields
- * @task core Core Properties and Field Identity
- * @task proxy Field Proxies
- * @task context Contextual Data
- * @task storage Field Storage
- * @task appsearch Integration with ApplicationSearch
- * @task appxaction Integration with ApplicationTransactions
- * @task edit Integration with edit views
- * @task view Integration with property views
- * @task list Integration with list views
+ * @task apps Building Applications with Custom Fields
+ * @task core Core Properties and Field Identity
+ * @task proxy Field Proxies
+ * @task context Contextual Data
+ * @task storage Field Storage
+ * @task edit Integration with Edit Views
+ * @task view Integration with Property Views
+ * @task list Integration with List views
+ * @task appsearch Integration with ApplicationSearch
+ * @task appxaction Integration with ApplicationTransactions
+ * @task globalsearch Integration with Global Search
*/
abstract class PhabricatorCustomField {
@@ -25,6 +26,7 @@
const ROLE_EDIT = 'edit';
const ROLE_VIEW = 'view';
const ROLE_LIST = 'list';
+ const ROLE_GLOBALSEARCH = 'GlobalSearch';
/* -( Building Applications with Custom Fields )--------------------------- */
@@ -253,6 +255,8 @@
return $this->shouldAppearInPropertyView();
case self::ROLE_LIST:
return $this->shouldAppearInListView();
+ case self::ROLE_GLOBALSEARCH:
+ return $this->shouldAppearInGlobalSearch();
case self::ROLE_DEFAULT:
return true;
default:
@@ -1091,4 +1095,30 @@
}
+/* -( Global Search )------------------------------------------------------ */
+
+
+ /**
+ * @task globalsearch
+ */
+ public function shouldAppearInGlobalSearch() {
+ if ($this->proxy) {
+ return $this->proxy->shouldAppearInGlobalSearch();
+ }
+ return false;
+ }
+
+
+ /**
+ * @task globalsearch
+ */
+ public function updateAbstractDocument(
+ PhabricatorSearchAbstractDocument $document) {
+ if ($this->proxy) {
+ return $this->proxy->updateAbstractDocument($document);
+ }
+ return $document;
+ }
+
+
}
Index: src/infrastructure/customfield/field/PhabricatorCustomFieldList.php
===================================================================
--- src/infrastructure/customfield/field/PhabricatorCustomFieldList.php
+++ src/infrastructure/customfield/field/PhabricatorCustomFieldList.php
@@ -52,7 +52,7 @@
}
if (!$keys) {
- return;
+ return $this;
}
// NOTE: We assume all fields share the same storage. This isn't guaranteed
@@ -79,6 +79,8 @@
$field->setValueFromStorage(null);
}
}
+
+ return $this;
}
public function appendFieldsToForm(AphrontFormView $form) {
@@ -304,4 +306,19 @@
$any_index->saveTransaction();
}
+ public function updateAbstractDocument(
+ PhabricatorSearchAbstractDocument $document) {
+
+ $role = PhabricatorCustomField::ROLE_GLOBALSEARCH;
+ foreach ($this->getFields() as $field) {
+ if (!$field->shouldEnableForRole($role)) {
+ continue;
+ }
+ $field->updateAbstractDocument($document);
+ }
+
+ return $document;
+ }
+
+
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Oct 22, 1:47 AM (4 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6721262
Default Alt Text
D8346.diff (12 KB)
Attached To
Mode
D8346: Use ApplicationTransactions/CustomField to power Differential global search
Attached
Detach File
Event Timeline
Log In to Comment