1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 00:42:41 +01:00

Separate fulltext engine extensions into "enrich" and "index" phases

Summary:
Ref T12819. Some of the extensions "enrich" the document (adding more fields or relationships), while others "index" it (insert it into some kind of index for later searching).

Currently, these are all muddled under a single "index" phase. However, the Ferret extension cares about fields and relationships which other extensions may add.

Split this into two phases: "enrich" adds fields and relationships so other extensions can read them later if they want. "Index" happens after the document is built and has all the fields and relationships.

The specific problem this solves is that comments may not have been added to the document when the Ferret extension runs. By moving them to the "enrich" phase, the Ferret engine will be able to see and index comments.

Test Plan: Ran `bin/search index ...`, grepped for `indexFulltextDocument`.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12819

Differential Revision: https://secure.phabricator.com/D18513
This commit is contained in:
epriestley 2017-09-01 09:19:01 -07:00
parent ab99222f28
commit f4f73e0a7e
7 changed files with 41 additions and 16 deletions

View file

@ -9,11 +9,11 @@ final class PhabricatorProjectsFulltextEngineExtension
return pht('Projects');
}
public function shouldIndexFulltextObject($object) {
public function shouldEnrichFulltextObject($object) {
return ($object instanceof PhabricatorProjectInterface);
}
public function indexFulltextObject(
public function enrichFulltextObject(
$object,
PhabricatorSearchAbstractDocument $document) {

View file

@ -9,7 +9,7 @@ final class PhabricatorLiskFulltextEngineExtension
return pht('Lisk Builtin Properties');
}
public function shouldIndexFulltextObject($object) {
public function shouldEnrichFulltextObject($object) {
if (!($object instanceof PhabricatorLiskDAO)) {
return false;
}
@ -21,7 +21,7 @@ final class PhabricatorLiskFulltextEngineExtension
return true;
}
public function indexFulltextObject(
public function enrichFulltextObject(
$object,
PhabricatorSearchAbstractDocument $document) {

View file

@ -26,9 +26,16 @@ abstract class PhabricatorFulltextEngine
$object = $this->getObject();
$extensions = PhabricatorFulltextEngineExtension::getAllExtensions();
$enrich_extensions = array();
$index_extensions = array();
foreach ($extensions as $key => $extension) {
if (!$extension->shouldIndexFulltextObject($object)) {
unset($extensions[$key]);
if ($extension->shouldEnrichFulltextObject($object)) {
$enrich_extensions[] = $extension;
}
if ($extension->shouldIndexFulltextObject($object)) {
$index_extensions[] = $extension;
}
}
@ -36,7 +43,11 @@ abstract class PhabricatorFulltextEngine
$this->buildAbstractDocument($document, $object);
foreach ($extensions as $extension) {
foreach ($enrich_extensions as $extension) {
$extension->enrichFulltextObject($object, $document);
}
foreach ($index_extensions as $extension) {
$extension->indexFulltextObject($object, $document);
}

View file

@ -12,11 +12,25 @@ abstract class PhabricatorFulltextEngineExtension extends Phobject {
abstract public function getExtensionName();
abstract public function shouldIndexFulltextObject($object);
public function shouldEnrichFulltextObject($object) {
return false;
}
abstract public function indexFulltextObject(
public function enrichFulltextObject(
$object,
PhabricatorSearchAbstractDocument $document);
PhabricatorSearchAbstractDocument $document) {
return;
}
public function shouldIndexFulltextObject($object) {
return false;
}
public function indexFulltextObject(
$object,
PhabricatorSearchAbstractDocument $document) {
return;
}
final public static function getAllExtensions() {
return id(new PhutilClassMapQuery())

View file

@ -9,11 +9,11 @@ final class PhabricatorSubscriptionsFulltextEngineExtension
return pht('Subscribers');
}
public function shouldIndexFulltextObject($object) {
public function shouldEnrichFulltextObject($object) {
return ($object instanceof PhabricatorSubscribableInterface);
}
public function indexFulltextObject(
public function enrichFulltextObject(
$object,
PhabricatorSearchAbstractDocument $document) {

View file

@ -9,11 +9,11 @@ final class PhabricatorTransactionsFulltextEngineExtension
return pht('Comments');
}
public function shouldIndexFulltextObject($object) {
public function shouldEnrichFulltextObject($object) {
return ($object instanceof PhabricatorApplicationTransactionInterface);
}
public function indexFulltextObject(
public function enrichFulltextObject(
$object,
PhabricatorSearchAbstractDocument $document) {

View file

@ -9,11 +9,11 @@ final class PhabricatorCustomFieldFulltextEngineExtension
return pht('Custom Fields');
}
public function shouldIndexFulltextObject($object) {
public function shouldEnrichFulltextObject($object) {
return ($object instanceof PhabricatorCustomFieldInterface);
}
public function indexFulltextObject(
public function enrichFulltextObject(
$object,
PhabricatorSearchAbstractDocument $document) {