Add support for differential field specifications to be indexed in search
Summary: ...and do so for a few fields -- summary, test plan, and revert plan. Test Plan: added NATASHA and BULLWINKLE to summary and test plan of existing diff. Diff showed up in search! Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T654 Differential Revision: https://secure.phabricator.com/D3915
This commit is contained in:
@@ -383,6 +383,31 @@ abstract class DifferentialFieldSpecification {
|
||||
return $key;
|
||||
}
|
||||
|
||||
/* -( Extending the Search Interface )------------------------------------ */
|
||||
|
||||
/**
|
||||
* @task search
|
||||
*/
|
||||
public function shouldAddToSearchIndex() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @task search
|
||||
*/
|
||||
public function getValueForSearchIndex() {
|
||||
throw new DifferentialFieldSpecificationIncompleteException($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* NOTE: Keys *must be* 4 characters for
|
||||
* @{class:PhabricatorSearchEngineMySQL}.
|
||||
*
|
||||
* @task search
|
||||
*/
|
||||
public function getKeyForSearchIndex() {
|
||||
throw new DifferentialFieldSpecificationIncompleteException($this);
|
||||
}
|
||||
|
||||
/* -( Extending Commit Messages )------------------------------------------ */
|
||||
|
||||
|
||||
@@ -95,4 +95,16 @@ final class DifferentialRevertPlanFieldSpecification
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function shouldAddToSearchIndex() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getValueForSearchIndex() {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function getKeyForSearchIndex() {
|
||||
return 'rpln';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -70,4 +70,16 @@ final class DifferentialSummaryFieldSpecification
|
||||
return $this->summary;
|
||||
}
|
||||
|
||||
public function shouldAddToSearchIndex() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getValueForSearchIndex() {
|
||||
return $this->summary;
|
||||
}
|
||||
|
||||
public function getKeyForSearchIndex() {
|
||||
return PhabricatorSearchField::FIELD_BODY;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -103,8 +103,22 @@ final class DifferentialTestPlanFieldSpecification
|
||||
return "TEST PLAN\n".preg_replace('/^/m', ' ', $this->plan);
|
||||
}
|
||||
|
||||
public function shouldAddToSearchIndex() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getValueForSearchIndex() {
|
||||
return $this->plan;
|
||||
}
|
||||
|
||||
public function getKeyForSearchIndex() {
|
||||
return 'tpln';
|
||||
}
|
||||
|
||||
private function isRequired() {
|
||||
return PhabricatorEnv::getEnvConfig('differential.require-test-plan-field');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ final class PhabricatorSearchField {
|
||||
|
||||
const FIELD_TITLE = 'titl';
|
||||
const FIELD_BODY = 'body';
|
||||
const FIELD_TEST_PLAN = 'tpln';
|
||||
const FIELD_COMMENT = 'cmnt';
|
||||
|
||||
}
|
||||
|
||||
@@ -14,12 +14,23 @@ final class PhabricatorSearchDifferentialIndexer
|
||||
$doc->setDocumentCreated($rev->getDateCreated());
|
||||
$doc->setDocumentModified($rev->getDateModified());
|
||||
|
||||
$doc->addField(
|
||||
PhabricatorSearchField::FIELD_BODY,
|
||||
$rev->getSummary());
|
||||
$doc->addField(
|
||||
PhabricatorSearchField::FIELD_TEST_PLAN,
|
||||
$rev->getTestPlan());
|
||||
$aux_fields = DifferentialFieldSelector::newSelector()
|
||||
->getFieldSpecifications();
|
||||
foreach ($aux_fields as $key => $aux_field) {
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user