1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-10 14:51:06 +01:00

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:
Bob Trahan 2012-11-07 13:31:52 -08:00
parent e53ca45fd8
commit 73bc34b26d
6 changed files with 80 additions and 7 deletions

View file

@ -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 )------------------------------------------ */

View file

@ -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';
}
}

View file

@ -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;
}
}

View file

@ -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');
}
}

View file

@ -7,7 +7,6 @@ final class PhabricatorSearchField {
const FIELD_TITLE = 'titl';
const FIELD_BODY = 'body';
const FIELD_TEST_PLAN = 'tpln';
const FIELD_COMMENT = 'cmnt';
}

View file

@ -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,