From 2218caee0f504f461557ecd0b518ede957172472 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 7 Sep 2017 11:03:39 -0700 Subject: [PATCH] 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 --- src/__phutil_library_map__.php | 36 ------ .../PhabricatorConfigCoreSchemaSpec.php | 8 ++ .../schema/PhabricatorConfigSchemaSpec.php | 20 ++++ .../DifferentialRevisionFerretEngine.php | 12 +- .../DifferentialRevisionFerretDocument.php | 14 --- .../DifferentialRevisionFerretField.php | 14 --- .../DifferentialRevisionFerretNgrams.php | 14 --- .../search/FundInitiativeFerretEngine.php | 12 +- .../storage/FundInitiativeFerretDocument.php | 14 --- .../storage/FundInitiativeFerretField.php | 14 --- .../storage/FundInitiativeFerretNgrams.php | 14 --- .../search/ManiphestTaskFerretEngine.php | 12 +- .../storage/ManiphestTaskFerretDocument.php | 14 --- .../storage/ManiphestTaskFerretField.php | 14 --- .../storage/ManiphestTaskFerretNgrams.php | 14 --- .../PassphraseCredentialFerretEngine.php | 12 +- .../PassphraseCredentialFerretDocument.php | 14 --- .../PassphraseCredentialFerretField.php | 14 --- .../PassphraseCredentialFerretNgrams.php | 14 --- .../search/PhabricatorUserFerretEngine.php | 12 +- .../storage/PhabricatorUserFerretDocument.php | 14 --- .../storage/PhabricatorUserFerretField.php | 14 --- .../storage/PhabricatorUserFerretNgrams.php | 14 --- ...abricatorFerretFulltextEngineExtension.php | 77 ++++++------ .../ferret/PhabricatorFerretDocument.php | 52 -------- .../search/ferret/PhabricatorFerretEngine.php | 112 +++++++++++++++++- .../search/ferret/PhabricatorFerretField.php | 39 ------ .../search/ferret/PhabricatorFerretNgrams.php | 35 ------ ...PhabricatorCursorPagedPolicyAwareQuery.php | 13 +- 29 files changed, 207 insertions(+), 455 deletions(-) delete mode 100644 src/applications/differential/storage/DifferentialRevisionFerretDocument.php delete mode 100644 src/applications/differential/storage/DifferentialRevisionFerretField.php delete mode 100644 src/applications/differential/storage/DifferentialRevisionFerretNgrams.php delete mode 100644 src/applications/fund/storage/FundInitiativeFerretDocument.php delete mode 100644 src/applications/fund/storage/FundInitiativeFerretField.php delete mode 100644 src/applications/fund/storage/FundInitiativeFerretNgrams.php delete mode 100644 src/applications/maniphest/storage/ManiphestTaskFerretDocument.php delete mode 100644 src/applications/maniphest/storage/ManiphestTaskFerretField.php delete mode 100644 src/applications/maniphest/storage/ManiphestTaskFerretNgrams.php delete mode 100644 src/applications/passphrase/storage/PassphraseCredentialFerretDocument.php delete mode 100644 src/applications/passphrase/storage/PassphraseCredentialFerretField.php delete mode 100644 src/applications/passphrase/storage/PassphraseCredentialFerretNgrams.php delete mode 100644 src/applications/people/storage/PhabricatorUserFerretDocument.php delete mode 100644 src/applications/people/storage/PhabricatorUserFerretField.php delete mode 100644 src/applications/people/storage/PhabricatorUserFerretNgrams.php delete mode 100644 src/applications/search/ferret/PhabricatorFerretDocument.php delete mode 100644 src/applications/search/ferret/PhabricatorFerretField.php delete mode 100644 src/applications/search/ferret/PhabricatorFerretNgrams.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 3e498d6273..1ffe418b5c 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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( diff --git a/src/applications/config/schema/PhabricatorConfigCoreSchemaSpec.php b/src/applications/config/schema/PhabricatorConfigCoreSchemaSpec.php index 4219ad2cb4..0d8d743649 100644 --- a/src/applications/config/schema/PhabricatorConfigCoreSchemaSpec.php +++ b/src/applications/config/schema/PhabricatorConfigCoreSchemaSpec.php @@ -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); + } } } diff --git a/src/applications/config/schema/PhabricatorConfigSchemaSpec.php b/src/applications/config/schema/PhabricatorConfigSchemaSpec.php index 49a99ab03a..b24adf27cd 100644 --- a/src/applications/config/schema/PhabricatorConfigSchemaSpec.php +++ b/src/applications/config/schema/PhabricatorConfigSchemaSpec.php @@ -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, diff --git a/src/applications/differential/search/DifferentialRevisionFerretEngine.php b/src/applications/differential/search/DifferentialRevisionFerretEngine.php index ebe59c2780..2fc7d5905e 100644 --- a/src/applications/differential/search/DifferentialRevisionFerretEngine.php +++ b/src/applications/differential/search/DifferentialRevisionFerretEngine.php @@ -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() { diff --git a/src/applications/differential/storage/DifferentialRevisionFerretDocument.php b/src/applications/differential/storage/DifferentialRevisionFerretDocument.php deleted file mode 100644 index ae8571f625..0000000000 --- a/src/applications/differential/storage/DifferentialRevisionFerretDocument.php +++ /dev/null @@ -1,14 +0,0 @@ -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); } diff --git a/src/applications/search/ferret/PhabricatorFerretDocument.php b/src/applications/search/ferret/PhabricatorFerretDocument.php deleted file mode 100644 index 6f25eb93b6..0000000000 --- a/src/applications/search/ferret/PhabricatorFerretDocument.php +++ /dev/null @@ -1,52 +0,0 @@ - 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"; - } - -} diff --git a/src/applications/search/ferret/PhabricatorFerretEngine.php b/src/applications/search/ferret/PhabricatorFerretEngine.php index eb40b70e58..219130c02c 100644 --- a/src/applications/search/ferret/PhabricatorFerretEngine.php +++ b/src/applications/search/ferret/PhabricatorFerretEngine.php @@ -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'), + ), + ); + } + } diff --git a/src/applications/search/ferret/PhabricatorFerretField.php b/src/applications/search/ferret/PhabricatorFerretField.php deleted file mode 100644 index be39e745ed..0000000000 --- a/src/applications/search/ferret/PhabricatorFerretField.php +++ /dev/null @@ -1,39 +0,0 @@ - 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"; - } - -} diff --git a/src/applications/search/ferret/PhabricatorFerretNgrams.php b/src/applications/search/ferret/PhabricatorFerretNgrams.php deleted file mode 100644 index 9e28f96cb6..0000000000 --- a/src/applications/search/ferret/PhabricatorFerretNgrams.php +++ /dev/null @@ -1,35 +0,0 @@ - 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"; - } - -} diff --git a/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php b/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php index 42e6ed7b4e..18e860ebb9 100644 --- a/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php +++ b/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php @@ -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,