1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 05:50:55 +01:00

Reduce the amount of boilerplate that implementing FerretInterface requires

Summary:
See brief discussion in D18554. All the index tables are the same for every application (and, at this point, seem unlikely to change) and we never actually pass these objects around (they're only used internally).

In some other cases (like Transactions) not every application has the same tables (for example, Differential has extra field for inline comments), and/or we pass the objects around (lots of stuff uses `$xactions` directly).

However, in this case, and in Edges, we don't interact with any representation of the database state directly in much of the code, and it doesn't change from application to application.

Just automatically define document, field, and ngram tables for anything which implements `FerretInterface`. This makes the query and index logic a tiny bit messier but lets us delete a ton of boilerplate classes.

Test Plan: Indexed objects, searched for objects. Same results as before with much less code. Ran `bin/storage upgrade`, got a clean bill of health.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12819

Differential Revision: https://secure.phabricator.com/D18559
This commit is contained in:
epriestley 2017-09-07 11:03:39 -07:00
parent 2020c1e7bd
commit 2218caee0f
29 changed files with 207 additions and 455 deletions

View file

@ -532,10 +532,7 @@ phutil_register_library_map(array(
'DifferentialRevisionEditConduitAPIMethod' => 'applications/differential/conduit/DifferentialRevisionEditConduitAPIMethod.php',
'DifferentialRevisionEditController' => 'applications/differential/controller/DifferentialRevisionEditController.php',
'DifferentialRevisionEditEngine' => 'applications/differential/editor/DifferentialRevisionEditEngine.php',
'DifferentialRevisionFerretDocument' => 'applications/differential/storage/DifferentialRevisionFerretDocument.php',
'DifferentialRevisionFerretEngine' => 'applications/differential/search/DifferentialRevisionFerretEngine.php',
'DifferentialRevisionFerretField' => 'applications/differential/storage/DifferentialRevisionFerretField.php',
'DifferentialRevisionFerretNgrams' => 'applications/differential/storage/DifferentialRevisionFerretNgrams.php',
'DifferentialRevisionFulltextEngine' => 'applications/differential/search/DifferentialRevisionFulltextEngine.php',
'DifferentialRevisionGraph' => 'infrastructure/graph/DifferentialRevisionGraph.php',
'DifferentialRevisionHasChildRelationship' => 'applications/differential/relationships/DifferentialRevisionHasChildRelationship.php',
@ -1153,10 +1150,7 @@ phutil_register_library_map(array(
'FundInitiativeEditController' => 'applications/fund/controller/FundInitiativeEditController.php',
'FundInitiativeEditEngine' => 'applications/fund/editor/FundInitiativeEditEngine.php',
'FundInitiativeEditor' => 'applications/fund/editor/FundInitiativeEditor.php',
'FundInitiativeFerretDocument' => 'applications/fund/storage/FundInitiativeFerretDocument.php',
'FundInitiativeFerretEngine' => 'applications/fund/search/FundInitiativeFerretEngine.php',
'FundInitiativeFerretField' => 'applications/fund/storage/FundInitiativeFerretField.php',
'FundInitiativeFerretNgrams' => 'applications/fund/storage/FundInitiativeFerretNgrams.php',
'FundInitiativeFulltextEngine' => 'applications/fund/search/FundInitiativeFulltextEngine.php',
'FundInitiativeListController' => 'applications/fund/controller/FundInitiativeListController.php',
'FundInitiativeMerchantTransaction' => 'applications/fund/xaction/FundInitiativeMerchantTransaction.php',
@ -1539,10 +1533,7 @@ phutil_register_library_map(array(
'ManiphestTaskEditBulkJobType' => 'applications/maniphest/bulk/ManiphestTaskEditBulkJobType.php',
'ManiphestTaskEditController' => 'applications/maniphest/controller/ManiphestTaskEditController.php',
'ManiphestTaskEditEngineLock' => 'applications/maniphest/editor/ManiphestTaskEditEngineLock.php',
'ManiphestTaskFerretDocument' => 'applications/maniphest/storage/ManiphestTaskFerretDocument.php',
'ManiphestTaskFerretEngine' => 'applications/maniphest/search/ManiphestTaskFerretEngine.php',
'ManiphestTaskFerretField' => 'applications/maniphest/storage/ManiphestTaskFerretField.php',
'ManiphestTaskFerretNgrams' => 'applications/maniphest/storage/ManiphestTaskFerretNgrams.php',
'ManiphestTaskFulltextEngine' => 'applications/maniphest/search/ManiphestTaskFulltextEngine.php',
'ManiphestTaskGraph' => 'infrastructure/graph/ManiphestTaskGraph.php',
'ManiphestTaskHasCommitEdgeType' => 'applications/maniphest/edge/ManiphestTaskHasCommitEdgeType.php',
@ -1840,10 +1831,7 @@ phutil_register_library_map(array(
'PassphraseCredentialDestroyController' => 'applications/passphrase/controller/PassphraseCredentialDestroyController.php',
'PassphraseCredentialDestroyTransaction' => 'applications/passphrase/xaction/PassphraseCredentialDestroyTransaction.php',
'PassphraseCredentialEditController' => 'applications/passphrase/controller/PassphraseCredentialEditController.php',
'PassphraseCredentialFerretDocument' => 'applications/passphrase/storage/PassphraseCredentialFerretDocument.php',
'PassphraseCredentialFerretEngine' => 'applications/passphrase/search/PassphraseCredentialFerretEngine.php',
'PassphraseCredentialFerretField' => 'applications/passphrase/storage/PassphraseCredentialFerretField.php',
'PassphraseCredentialFerretNgrams' => 'applications/passphrase/storage/PassphraseCredentialFerretNgrams.php',
'PassphraseCredentialFulltextEngine' => 'applications/passphrase/search/PassphraseCredentialFulltextEngine.php',
'PassphraseCredentialListController' => 'applications/passphrase/controller/PassphraseCredentialListController.php',
'PassphraseCredentialLockController' => 'applications/passphrase/controller/PassphraseCredentialLockController.php',
@ -2841,15 +2829,12 @@ phutil_register_library_map(array(
'PhabricatorFeedStoryNotification' => 'applications/notification/storage/PhabricatorFeedStoryNotification.php',
'PhabricatorFeedStoryPublisher' => 'applications/feed/PhabricatorFeedStoryPublisher.php',
'PhabricatorFeedStoryReference' => 'applications/feed/storage/PhabricatorFeedStoryReference.php',
'PhabricatorFerretDocument' => 'applications/search/ferret/PhabricatorFerretDocument.php',
'PhabricatorFerretEngine' => 'applications/search/ferret/PhabricatorFerretEngine.php',
'PhabricatorFerretEngineTestCase' => 'applications/search/ferret/__tests__/PhabricatorFerretEngineTestCase.php',
'PhabricatorFerretField' => 'applications/search/ferret/PhabricatorFerretField.php',
'PhabricatorFerretFulltextEngineExtension' => 'applications/search/engineextension/PhabricatorFerretFulltextEngineExtension.php',
'PhabricatorFerretFulltextStorageEngine' => 'applications/search/fulltextstorage/PhabricatorFerretFulltextStorageEngine.php',
'PhabricatorFerretInterface' => 'applications/search/ferret/PhabricatorFerretInterface.php',
'PhabricatorFerretMetadata' => 'applications/search/ferret/PhabricatorFerretMetadata.php',
'PhabricatorFerretNgrams' => 'applications/search/ferret/PhabricatorFerretNgrams.php',
'PhabricatorFerretSearchEngineExtension' => 'applications/search/engineextension/PhabricatorFerretSearchEngineExtension.php',
'PhabricatorFile' => 'applications/files/storage/PhabricatorFile.php',
'PhabricatorFileAES256StorageFormat' => 'applications/files/format/PhabricatorFileAES256StorageFormat.php',
@ -4265,10 +4250,7 @@ phutil_register_library_map(array(
'PhabricatorUserEditorTestCase' => 'applications/people/editor/__tests__/PhabricatorUserEditorTestCase.php',
'PhabricatorUserEmail' => 'applications/people/storage/PhabricatorUserEmail.php',
'PhabricatorUserEmailTestCase' => 'applications/people/storage/__tests__/PhabricatorUserEmailTestCase.php',
'PhabricatorUserFerretDocument' => 'applications/people/storage/PhabricatorUserFerretDocument.php',
'PhabricatorUserFerretEngine' => 'applications/people/search/PhabricatorUserFerretEngine.php',
'PhabricatorUserFerretField' => 'applications/people/storage/PhabricatorUserFerretField.php',
'PhabricatorUserFerretNgrams' => 'applications/people/storage/PhabricatorUserFerretNgrams.php',
'PhabricatorUserFulltextEngine' => 'applications/people/search/PhabricatorUserFulltextEngine.php',
'PhabricatorUserIconField' => 'applications/people/customfield/PhabricatorUserIconField.php',
'PhabricatorUserLog' => 'applications/people/storage/PhabricatorUserLog.php',
@ -5564,10 +5546,7 @@ phutil_register_library_map(array(
'DifferentialRevisionEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
'DifferentialRevisionEditController' => 'DifferentialController',
'DifferentialRevisionEditEngine' => 'PhabricatorEditEngine',
'DifferentialRevisionFerretDocument' => 'PhabricatorFerretDocument',
'DifferentialRevisionFerretEngine' => 'PhabricatorFerretEngine',
'DifferentialRevisionFerretField' => 'PhabricatorFerretField',
'DifferentialRevisionFerretNgrams' => 'PhabricatorFerretNgrams',
'DifferentialRevisionFulltextEngine' => 'PhabricatorFulltextEngine',
'DifferentialRevisionGraph' => 'PhabricatorObjectGraph',
'DifferentialRevisionHasChildRelationship' => 'DifferentialRevisionRelationship',
@ -6248,10 +6227,7 @@ phutil_register_library_map(array(
'FundInitiativeEditController' => 'FundController',
'FundInitiativeEditEngine' => 'PhabricatorEditEngine',
'FundInitiativeEditor' => 'PhabricatorApplicationTransactionEditor',
'FundInitiativeFerretDocument' => 'PhabricatorFerretDocument',
'FundInitiativeFerretEngine' => 'PhabricatorFerretEngine',
'FundInitiativeFerretField' => 'PhabricatorFerretField',
'FundInitiativeFerretNgrams' => 'PhabricatorFerretNgrams',
'FundInitiativeFulltextEngine' => 'PhabricatorFulltextEngine',
'FundInitiativeListController' => 'FundController',
'FundInitiativeMerchantTransaction' => 'FundInitiativeTransactionType',
@ -6719,10 +6695,7 @@ phutil_register_library_map(array(
'ManiphestTaskEditBulkJobType' => 'PhabricatorWorkerBulkJobType',
'ManiphestTaskEditController' => 'ManiphestController',
'ManiphestTaskEditEngineLock' => 'PhabricatorEditEngineLock',
'ManiphestTaskFerretDocument' => 'PhabricatorFerretDocument',
'ManiphestTaskFerretEngine' => 'PhabricatorFerretEngine',
'ManiphestTaskFerretField' => 'PhabricatorFerretField',
'ManiphestTaskFerretNgrams' => 'PhabricatorFerretNgrams',
'ManiphestTaskFulltextEngine' => 'PhabricatorFulltextEngine',
'ManiphestTaskGraph' => 'PhabricatorObjectGraph',
'ManiphestTaskHasCommitEdgeType' => 'PhabricatorEdgeType',
@ -7049,10 +7022,7 @@ phutil_register_library_map(array(
'PassphraseCredentialDestroyController' => 'PassphraseController',
'PassphraseCredentialDestroyTransaction' => 'PassphraseCredentialTransactionType',
'PassphraseCredentialEditController' => 'PassphraseController',
'PassphraseCredentialFerretDocument' => 'PhabricatorFerretDocument',
'PassphraseCredentialFerretEngine' => 'PhabricatorFerretEngine',
'PassphraseCredentialFerretField' => 'PhabricatorFerretField',
'PassphraseCredentialFerretNgrams' => 'PhabricatorFerretNgrams',
'PassphraseCredentialFulltextEngine' => 'PhabricatorFulltextEngine',
'PassphraseCredentialListController' => 'PassphraseController',
'PassphraseCredentialLockController' => 'PassphraseController',
@ -8192,14 +8162,11 @@ phutil_register_library_map(array(
'PhabricatorFeedStoryNotification' => 'PhabricatorFeedDAO',
'PhabricatorFeedStoryPublisher' => 'Phobject',
'PhabricatorFeedStoryReference' => 'PhabricatorFeedDAO',
'PhabricatorFerretDocument' => 'PhabricatorSearchDAO',
'PhabricatorFerretEngine' => 'Phobject',
'PhabricatorFerretEngineTestCase' => 'PhabricatorTestCase',
'PhabricatorFerretField' => 'PhabricatorSearchDAO',
'PhabricatorFerretFulltextEngineExtension' => 'PhabricatorFulltextEngineExtension',
'PhabricatorFerretFulltextStorageEngine' => 'PhabricatorFulltextStorageEngine',
'PhabricatorFerretMetadata' => 'Phobject',
'PhabricatorFerretNgrams' => 'PhabricatorSearchDAO',
'PhabricatorFerretSearchEngineExtension' => 'PhabricatorSearchEngineExtension',
'PhabricatorFile' => array(
'PhabricatorFileDAO',
@ -9885,10 +9852,7 @@ phutil_register_library_map(array(
'PhabricatorUserEditorTestCase' => 'PhabricatorTestCase',
'PhabricatorUserEmail' => 'PhabricatorUserDAO',
'PhabricatorUserEmailTestCase' => 'PhabricatorTestCase',
'PhabricatorUserFerretDocument' => 'PhabricatorFerretDocument',
'PhabricatorUserFerretEngine' => 'PhabricatorFerretEngine',
'PhabricatorUserFerretField' => 'PhabricatorFerretField',
'PhabricatorUserFerretNgrams' => 'PhabricatorFerretNgrams',
'PhabricatorUserFulltextEngine' => 'PhabricatorFulltextEngine',
'PhabricatorUserIconField' => 'PhabricatorUserCustomField',
'PhabricatorUserLog' => array(

View file

@ -42,5 +42,13 @@ final class PhabricatorConfigCoreSchemaSpec
));
}
$ferret_objects = id(new PhutilClassMapQuery())
->setAncestorClass('PhabricatorFerretInterface')
->execute();
foreach ($ferret_objects as $ferret_object) {
$engine = $ferret_object->newFerretEngine();
$this->buildFerretIndexSchema($engine);
}
}
}

View file

@ -55,6 +55,26 @@ abstract class PhabricatorConfigSchemaSpec extends Phobject {
$object->getSchemaKeys());
}
protected function buildFerretIndexSchema(PhabricatorFerretEngine $engine) {
$this->buildRawSchema(
$engine->getApplicationName(),
$engine->getDocumentTableName(),
$engine->getDocumentSchemaColumns(),
$engine->getDocumentSchemaKeys());
$this->buildRawSchema(
$engine->getApplicationName(),
$engine->getFieldTableName(),
$engine->getFieldSchemaColumns(),
$engine->getFieldSchemaKeys());
$this->buildRawSchema(
$engine->getApplicationName(),
$engine->getNgramsTableName(),
$engine->getNgramsSchemaColumns(),
$engine->getNgramsSchemaKeys());
}
protected function buildRawSchema(
$database_name,
$table_name,

View file

@ -3,16 +3,12 @@
final class DifferentialRevisionFerretEngine
extends PhabricatorFerretEngine {
public function newNgramsObject() {
return new DifferentialRevisionFerretNgrams();
public function getApplicationName() {
return 'differential';
}
public function newDocumentObject() {
return new DifferentialRevisionFerretDocument();
}
public function newFieldObject() {
return new DifferentialRevisionFerretField();
public function getScopeName() {
return 'revision';
}
public function newSearchEngine() {

View file

@ -1,14 +0,0 @@
<?php
final class DifferentialRevisionFerretDocument
extends PhabricatorFerretDocument {
public function getApplicationName() {
return 'differential';
}
public function getIndexKey() {
return 'revision';
}
}

View file

@ -1,14 +0,0 @@
<?php
final class DifferentialRevisionFerretField
extends PhabricatorFerretField {
public function getApplicationName() {
return 'differential';
}
public function getIndexKey() {
return 'revision';
}
}

View file

@ -1,14 +0,0 @@
<?php
final class DifferentialRevisionFerretNgrams
extends PhabricatorFerretNgrams {
public function getApplicationName() {
return 'differential';
}
public function getIndexKey() {
return 'revision';
}
}

View file

@ -3,16 +3,12 @@
final class FundInitiativeFerretEngine
extends PhabricatorFerretEngine {
public function newNgramsObject() {
return new FundInitiativeFerretNgrams();
public function getApplicationName() {
return 'fund';
}
public function newDocumentObject() {
return new FundInitiativeFerretDocument();
}
public function newFieldObject() {
return new FundInitiativeFerretField();
public function getScopeName() {
return 'initiative';
}
public function newSearchEngine() {

View file

@ -1,14 +0,0 @@
<?php
final class FundInitiativeFerretDocument
extends PhabricatorFerretDocument {
public function getApplicationName() {
return 'fund';
}
public function getIndexKey() {
return 'initiative';
}
}

View file

@ -1,14 +0,0 @@
<?php
final class FundInitiativeFerretField
extends PhabricatorFerretField {
public function getApplicationName() {
return 'fund';
}
public function getIndexKey() {
return 'initiative';
}
}

View file

@ -1,14 +0,0 @@
<?php
final class FundInitiativeFerretNgrams
extends PhabricatorFerretNgrams {
public function getApplicationName() {
return 'fund';
}
public function getIndexKey() {
return 'initiative';
}
}

View file

@ -3,16 +3,12 @@
final class ManiphestTaskFerretEngine
extends PhabricatorFerretEngine {
public function newNgramsObject() {
return new ManiphestTaskFerretNgrams();
public function getApplicationName() {
return 'maniphest';
}
public function newDocumentObject() {
return new ManiphestTaskFerretDocument();
}
public function newFieldObject() {
return new ManiphestTaskFerretField();
public function getScopeName() {
return 'task';
}
public function newSearchEngine() {

View file

@ -1,14 +0,0 @@
<?php
final class ManiphestTaskFerretDocument
extends PhabricatorFerretDocument {
public function getApplicationName() {
return 'maniphest';
}
public function getIndexKey() {
return 'task';
}
}

View file

@ -1,14 +0,0 @@
<?php
final class ManiphestTaskFerretField
extends PhabricatorFerretField {
public function getApplicationName() {
return 'maniphest';
}
public function getIndexKey() {
return 'task';
}
}

View file

@ -1,14 +0,0 @@
<?php
final class ManiphestTaskFerretNgrams
extends PhabricatorFerretNgrams {
public function getApplicationName() {
return 'maniphest';
}
public function getIndexKey() {
return 'task';
}
}

View file

@ -3,16 +3,12 @@
final class PassphraseCredentialFerretEngine
extends PhabricatorFerretEngine {
public function newNgramsObject() {
return new PassphraseCredentialFerretNgrams();
public function getApplicationName() {
return 'passphrase';
}
public function newDocumentObject() {
return new PassphraseCredentialFerretDocument();
}
public function newFieldObject() {
return new PassphraseCredentialFerretField();
public function getScopeName() {
return 'credential';
}
public function newSearchEngine() {

View file

@ -1,14 +0,0 @@
<?php
final class PassphraseCredentialFerretDocument
extends PhabricatorFerretDocument {
public function getApplicationName() {
return 'passphrase';
}
public function getIndexKey() {
return 'credential';
}
}

View file

@ -1,14 +0,0 @@
<?php
final class PassphraseCredentialFerretField
extends PhabricatorFerretField {
public function getApplicationName() {
return 'passphrase';
}
public function getIndexKey() {
return 'credential';
}
}

View file

@ -1,14 +0,0 @@
<?php
final class PassphraseCredentialFerretNgrams
extends PhabricatorFerretNgrams {
public function getApplicationName() {
return 'passphrase';
}
public function getIndexKey() {
return 'credential';
}
}

View file

@ -3,16 +3,12 @@
final class PhabricatorUserFerretEngine
extends PhabricatorFerretEngine {
public function newNgramsObject() {
return new PhabricatorUserFerretNgrams();
public function getApplicationName() {
return 'user';
}
public function newDocumentObject() {
return new PhabricatorUserFerretDocument();
}
public function newFieldObject() {
return new PhabricatorUserFerretField();
public function getScopeName() {
return 'user';
}
public function newSearchEngine() {

View file

@ -1,14 +0,0 @@
<?php
final class PhabricatorUserFerretDocument
extends PhabricatorFerretDocument {
public function getApplicationName() {
return 'user';
}
public function getIndexKey() {
return 'user';
}
}

View file

@ -1,14 +0,0 @@
<?php
final class PhabricatorUserFerretField
extends PhabricatorFerretField {
public function getApplicationName() {
return 'user';
}
public function getIndexKey() {
return 'user';
}
}

View file

@ -1,14 +0,0 @@
<?php
final class PhabricatorUserFerretNgrams
extends PhabricatorFerretNgrams {
public function getApplicationName() {
return 'user';
}
public function getIndexKey() {
return 'user';
}
}

View file

@ -47,14 +47,6 @@ final class PhabricatorFerretFulltextEngineExtension
}
}
$ferret_document = $engine->newDocumentObject()
->setObjectPHID($phid)
->setIsClosed($is_closed)
->setEpochCreated($document->getDocumentCreated())
->setEpochModified($document->getDocumentModified())
->setAuthorPHID($author_phid)
->setOwnerPHID($owner_phid);
$stemmer = $engine->newStemmer();
// Copy all of the "title" and "body" fields to create new "core" fields.
@ -133,33 +125,49 @@ final class PhabricatorFerretFulltextEngineExtension
$ngrams_source[] = $term_corpus;
}
$ferret_fields[] = $engine->newFieldObject()
->setFieldKey($key)
->setRawCorpus($raw_corpus)
->setTermCorpus($term_corpus)
->setNormalCorpus($normal_corpus);
$ferret_fields[] = array(
'fieldKey' => $key,
'rawCorpus' => $raw_corpus,
'termCorpus' => $term_corpus,
'normalCorpus' => $normal_corpus,
);
}
$ngrams_source = implode("\n", $ngrams_source);
$ngrams = $engine->getTermNgramsFromString($ngrams_source);
$ferret_document->openTransaction();
$object->openTransaction();
try {
$conn = $object->establishConnection('w');
$this->deleteOldDocument($engine, $object, $document);
$ferret_document->save();
queryfx(
$conn,
'INSERT INTO %T (objectPHID, isClosed, epochCreated, epochModified,
authorPHID, ownerPHID) VALUES (%s, %d, %d, %d, %ns, %ns)',
$engine->getDocumentTableName(),
$object->getPHID(),
$is_closed,
$document->getDocumentCreated(),
$document->getDocumentModified(),
$author_phid,
$owner_phid);
$document_id = $ferret_document->getID();
$document_id = $conn->getInsertID();
foreach ($ferret_fields as $ferret_field) {
$ferret_field
->setDocumentID($document_id)
->save();
queryfx(
$conn,
'INSERT INTO %T (documentID, fieldKey, rawCorpus, termCorpus,
normalCorpus) VALUES (%d, %s, %s, %s, %s)',
$engine->getFieldTableName(),
$document_id,
$ferret_field['fieldKey'],
$ferret_field['rawCorpus'],
$ferret_field['termCorpus'],
$ferret_field['normalCorpus']);
}
$ferret_ngrams = $engine->newNgramsObject();
$conn = $ferret_ngrams->establishConnection('w');
$sql = array();
foreach ($ngrams as $ngram) {
$sql[] = qsprintf(
@ -173,15 +181,15 @@ final class PhabricatorFerretFulltextEngineExtension
queryfx(
$conn,
'INSERT INTO %T (documentID, ngram) VALUES %Q',
$ferret_ngrams->getTableName(),
$engine->getNgramsTableName(),
$chunk);
}
} catch (Exception $ex) {
$ferret_document->killTransaction();
$object->killTransaction();
throw $ex;
}
$ferret_document->saveTransaction();
$object->saveTransaction();
}
@ -190,32 +198,35 @@ final class PhabricatorFerretFulltextEngineExtension
$object,
PhabricatorSearchAbstractDocument $document) {
$old_document = $engine->newDocumentObject()->loadOneWhere(
'objectPHID = %s',
$document->getPHID());
$conn = $object->establishConnection('w');
$old_document = queryfx_one(
$conn,
'SELECT * FROM %T WHERE objectPHID = %s',
$engine->getDocumentTableName(),
$object->getPHID());
if (!$old_document) {
return;
}
$conn = $old_document->establishConnection('w');
$old_id = $old_document->getID();
$old_id = $old_document['id'];
queryfx(
$conn,
'DELETE FROM %T WHERE id = %d',
$engine->newDocumentObject()->getTableName(),
$engine->getDocumentTableName(),
$old_id);
queryfx(
$conn,
'DELETE FROM %T WHERE documentID = %d',
$engine->newFieldObject()->getTableName(),
$engine->getFieldTableName(),
$old_id);
queryfx(
$conn,
'DELETE FROM %T WHERE documentID = %d',
$engine->newNgramsObject()->getTableName(),
$engine->getNgramsTableName(),
$old_id);
}

View file

@ -1,52 +0,0 @@
<?php
abstract class PhabricatorFerretDocument
extends PhabricatorSearchDAO {
protected $objectPHID;
protected $isClosed;
protected $authorPHID;
protected $ownerPHID;
protected $epochCreated;
protected $epochModified;
abstract public function getIndexKey();
protected function getConfiguration() {
return array(
self::CONFIG_TIMESTAMPS => false,
self::CONFIG_COLUMN_SCHEMA => array(
'isClosed' => 'bool',
'authorPHID' => 'phid?',
'ownerPHID' => 'phid?',
'epochCreated' => 'epoch',
'epochModified' => 'epoch',
),
self::CONFIG_KEY_SCHEMA => array(
'key_object' => array(
'columns' => array('objectPHID'),
'unique' => true,
),
'key_author' => array(
'columns' => array('authorPHID'),
),
'key_owner' => array(
'columns' => array('ownerPHID'),
),
'key_created' => array(
'columns' => array('epochCreated'),
),
'key_modified' => array(
'columns' => array('epochModified'),
),
),
) + parent::getConfiguration();
}
public function getTableName() {
$application = $this->getApplicationName();
$key = $this->getIndexKey();
return "{$application}_{$key}_fdocument";
}
}

View file

@ -2,9 +2,8 @@
abstract class PhabricatorFerretEngine extends Phobject {
abstract public function newNgramsObject();
abstract public function newDocumentObject();
abstract public function newFieldObject();
abstract public function getApplicationName();
abstract public function getScopeName();
abstract public function newSearchEngine();
public function getDefaultFunctionKey() {
@ -168,4 +167,111 @@ abstract class PhabricatorFerretEngine extends Phobject {
return $term_corpus;
}
/* -( Schema )------------------------------------------------------------- */
public function getDocumentTableName() {
$application = $this->getApplicationName();
$scope = $this->getScopeName();
return "{$application}_{$scope}_fdocument";
}
public function getDocumentSchemaColumns() {
return array(
'id' => 'auto',
'objectPHID' => 'phid',
'isClosed' => 'bool',
'authorPHID' => 'phid?',
'ownerPHID' => 'phid?',
'epochCreated' => 'epoch',
'epochModified' => 'epoch',
);
}
public function getDocumentSchemaKeys() {
return array(
'PRIMARY' => array(
'columns' => array('id'),
'unique' => true,
),
'key_object' => array(
'columns' => array('objectPHID'),
'unique' => true,
),
'key_author' => array(
'columns' => array('authorPHID'),
),
'key_owner' => array(
'columns' => array('ownerPHID'),
),
'key_created' => array(
'columns' => array('epochCreated'),
),
'key_modified' => array(
'columns' => array('epochModified'),
),
);
}
public function getFieldTableName() {
$application = $this->getApplicationName();
$scope = $this->getScopeName();
return "{$application}_{$scope}_ffield";
}
public function getFieldSchemaColumns() {
return array(
'id' => 'auto',
'documentID' => 'uint32',
'fieldKey' => 'text4',
'rawCorpus' => 'sort',
'termCorpus' => 'sort',
'normalCorpus' => 'sort',
);
}
public function getFieldSchemaKeys() {
return array(
'PRIMARY' => array(
'columns' => array('id'),
'unique' => true,
),
'key_documentfield' => array(
'columns' => array('documentID', 'fieldKey'),
'unique' => true,
),
);
}
public function getNgramsTableName() {
$application = $this->getApplicationName();
$scope = $this->getScopeName();
return "{$application}_{$scope}_fngrams";
}
public function getNgramsSchemaColumns() {
return array(
'id' => 'auto',
'documentID' => 'uint32',
'ngram' => 'char3',
);
}
public function getNgramsSchemaKeys() {
return array(
'PRIMARY' => array(
'columns' => array('id'),
'unique' => true,
),
'key_ngram' => array(
'columns' => array('ngram', 'documentID'),
),
'key_object' => array(
'columns' => array('documentID'),
),
);
}
}

View file

@ -1,39 +0,0 @@
<?php
abstract class PhabricatorFerretField
extends PhabricatorSearchDAO {
protected $documentID;
protected $fieldKey;
protected $rawCorpus;
protected $termCorpus;
protected $normalCorpus;
abstract public function getIndexKey();
protected function getConfiguration() {
return array(
self::CONFIG_TIMESTAMPS => false,
self::CONFIG_COLUMN_SCHEMA => array(
'documentID' => 'uint32',
'fieldKey' => 'text4',
'rawCorpus' => 'sort',
'termCorpus' => 'sort',
'normalCorpus' => 'sort',
),
self::CONFIG_KEY_SCHEMA => array(
'key_documentfield' => array(
'columns' => array('documentID', 'fieldKey'),
'unique' => true,
),
),
) + parent::getConfiguration();
}
public function getTableName() {
$application = $this->getApplicationName();
$key = $this->getIndexKey();
return "{$application}_{$key}_ffield";
}
}

View file

@ -1,35 +0,0 @@
<?php
abstract class PhabricatorFerretNgrams
extends PhabricatorSearchDAO {
protected $documentID;
protected $ngram;
abstract public function getIndexKey();
protected function getConfiguration() {
return array(
self::CONFIG_TIMESTAMPS => false,
self::CONFIG_COLUMN_SCHEMA => array(
'documentID' => 'uint32',
'ngram' => 'char3',
),
self::CONFIG_KEY_SCHEMA => array(
'key_ngram' => array(
'columns' => array('ngram', 'documentID'),
),
'key_object' => array(
'columns' => array('documentID'),
),
),
) + parent::getConfiguration();
}
public function getTableName() {
$application = $this->getApplicationName();
$key = $this->getIndexKey();
return "{$application}_{$key}_fngrams";
}
}

View file

@ -1623,8 +1623,7 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
$engine = $this->ferretEngine;
$stemmer = $engine->newStemmer();
$ngram_table = $engine->newNgramsObject();
$ngram_table_name = $ngram_table->getTableName();
$ngram_table = $engine->getNgramsTableName();
$flat = array();
foreach ($this->ferretTokens as $fulltext_token) {
@ -1680,7 +1679,7 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
foreach ($ngrams as $ngram) {
$flat[] = array(
'table' => $ngram_table_name,
'table' => $ngram_table,
'ngram' => $ngram,
);
}
@ -1702,14 +1701,14 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
$phid_column = qsprintf($conn, '%T', 'phid');
}
$document_table = $engine->newDocumentObject();
$field_table = $engine->newFieldObject();
$document_table = $engine->getDocumentTableName();
$field_table = $engine->getFieldTableName();
$joins = array();
$joins[] = qsprintf(
$conn,
'JOIN %T ft_doc ON ft_doc.objectPHID = %Q',
$document_table->getTableName(),
$document_table,
$phid_column);
$idx = 1;
@ -1736,7 +1735,7 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
$conn,
'JOIN %T %T ON ft_doc.id = %T.documentID
AND %T.fieldKey = %s',
$field_table->getTableName(),
$field_table,
$alias,
$alias,
$alias,