From b8e08f34f7ae24047ab2972a9bd5f9604ae30952 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 7 Aug 2011 15:14:23 -0700 Subject: [PATCH] Provide an indirection layer between documents and the search engine Summary: In preparation for adding another search engine (see T355): - Rename "executor" to "engine". - Move all engine-specific operations into the engine. Specifically, this means that indexing moves out of the document store and into the engine (it was sort of silly where it was before). - Split choice of an engine into an overridable "selector" class, a base API, and a concrete MySQL implementation (just like storage engine selection). - Make all callers go through the indirection layer. The default selector just unconditionally selects the MySQL engine, but now (with D786) I can build an Elastic Search engine and you guys can build a multi-target engine if you want and I don't get there fast enough. Test Plan: - Created a new document (task). - Searched for and found it. - Viewed index reconstruction. Reviewed By: jungejason Reviewers: jungejason, amckinley, tuomaspelkonen, aran CC: aran, jungejason, epriestley Differential Revision: 788 --- conf/default.conf.php | 17 +++++ src/__phutil_library_map__.php | 9 ++- .../DiffusionCommitListController.php | 4 +- .../controller/commitlist/__init__.php | 2 +- .../PhabricatorSearchIndexController.php | 4 +- .../search/controller/index/__init__.php | 2 +- .../search/PhabricatorSearchController.php | 4 +- .../search/controller/search/__init__.php | 2 +- .../engine/base/PhabricatorSearchEngine.php | 57 +++++++++++++++ .../{execute => engine}/base/__init__.php | 2 +- .../mysql/PhabricatorSearchEngineMySQL.php} | 72 ++++++++++++++++++- .../{execute => engine}/mysql/__init__.php | 4 +- .../base/PhabricatorSearchDocumentIndexer.php | 11 ++- .../search/index/indexer/base/__init__.php | 2 + .../PhabricatorSearchDifferentialIndexer.php | 2 +- .../index/indexer/differential/__init__.php | 1 - .../PhabricatorSearchManiphestIndexer.php | 2 +- .../index/indexer/maniphest/__init__.php | 1 - .../PhabricatorSearchPhrictionIndexer.php | 2 +- .../index/indexer/phriction/__init__.php | 1 - .../PhabricatorSearchCommitIndexer.php | 2 +- .../index/indexer/repository/__init__.php | 1 - .../user/PhabricatorSearchUserIndexer.php | 2 +- .../search/index/indexer/user/__init__.php | 1 - .../base/PhabricatorSearchEngineSelector.php | 32 +++++++++ .../search/selector/base/__init__.php | 14 ++++ ...habricatorDefaultSearchEngineSelector.php} | 7 +- .../search/selector/default/__init__.php | 13 ++++ .../document/PhabricatorSearchDocument.php | 70 ------------------ .../storage/document/document/__init__.php | 4 -- 30 files changed, 244 insertions(+), 103 deletions(-) create mode 100644 src/applications/search/engine/base/PhabricatorSearchEngine.php rename src/applications/search/{execute => engine}/base/__init__.php (65%) rename src/applications/search/{execute/mysql/PhabricatorSearchMySQLExecutor.php => engine/mysql/PhabricatorSearchEngineMySQL.php} (78%) rename src/applications/search/{execute => engine}/mysql/__init__.php (83%) create mode 100644 src/applications/search/selector/base/PhabricatorSearchEngineSelector.php create mode 100644 src/applications/search/selector/base/__init__.php rename src/applications/search/{execute/base/PhabricatorSearchExecutor.php => selector/default/PhabricatorDefaultSearchEngineSelector.php} (77%) create mode 100644 src/applications/search/selector/default/__init__.php diff --git a/conf/default.conf.php b/conf/default.conf.php index 55519bd8ae..623483da30 100644 --- a/conf/default.conf.php +++ b/conf/default.conf.php @@ -35,6 +35,7 @@ return array( // be 50x50px. 'user.default-profile-image-phid' => 'PHID-FILE-4d61229816cfe6f2b2a3', + // -- DarkConsole ----------------------------------------------------------- // // DarkConsole is a administrative debugging/profiling tool built into @@ -67,6 +68,7 @@ return array( 'github.application-secret', ), + // -- MySQL --------------------------------------------------------------- // // The username to use when connecting to MySQL. @@ -80,6 +82,7 @@ return array( // (e.g., db.example.com:1234). 'mysql.host' => 'localhost', + // -- Email ----------------------------------------------------------------- // // Some Phabricator tools send email notifications, e.g. when Differential @@ -322,6 +325,7 @@ return array( // behalf, silencing the warning. 'phabricator.timezone' => null, + // -- Files ----------------------------------------------------------------- // // Lists which uploaded file types may be viewed in the browser. If a file @@ -395,6 +399,18 @@ return array( // fits within configured limits. 'storage.engine-selector' => 'PhabricatorDefaultFileStorageEngineSelector', + +// -- Search ---------------------------------------------------------------- // + + // Phabricator uses a search engine selector to choose which search engine + // to use when indexing and reconstructing documents, and when executing + // queries. You can override the engine selector to provide a new selector + // class which can select some custom engine you implement, if you want to + // store your documents in some search engine which does not have default + // support. + 'search.engine-selector' => 'PhabricatorDefaultSearchEngineSelector', + + // -- Differential ---------------------------------------------------------- // 'differential.revision-custom-detail-renderer' => null, @@ -440,6 +456,7 @@ return array( // type. 'maniphest.custom-fields' => array(), + // -- Remarkup -------------------------------------------------------------- // // If you enable this, linked YouTube videos will be embeded inline. This has diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index ea4a2a5e7b..c25b4b5d61 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -336,6 +336,7 @@ phutil_register_library_map(array( 'PhabricatorDaemonTimelineConsoleController' => 'applications/daemon/controller/timeline', 'PhabricatorDaemonTimelineEventController' => 'applications/daemon/controller/timelineevent', 'PhabricatorDefaultFileStorageEngineSelector' => 'applications/files/engineselector/default', + 'PhabricatorDefaultSearchEngineSelector' => 'applications/search/selector/default', 'PhabricatorDifferenceEngine' => 'infrastructure/diff/engine', 'PhabricatorDirectoryCategory' => 'applications/directory/storage/category', 'PhabricatorDirectoryCategoryDeleteController' => 'applications/directory/controller/categorydelete', @@ -545,11 +546,12 @@ phutil_register_library_map(array( 'PhabricatorSearchDocumentField' => 'applications/search/storage/document/field', 'PhabricatorSearchDocumentIndexer' => 'applications/search/index/indexer/base', 'PhabricatorSearchDocumentRelationship' => 'applications/search/storage/document/relationship', - 'PhabricatorSearchExecutor' => 'applications/search/execute/base', + 'PhabricatorSearchEngine' => 'applications/search/engine/base', + 'PhabricatorSearchEngineMySQL' => 'applications/search/engine/mysql', + 'PhabricatorSearchEngineSelector' => 'applications/search/selector/base', 'PhabricatorSearchField' => 'applications/search/constants/field', 'PhabricatorSearchIndexController' => 'applications/search/controller/index', 'PhabricatorSearchManiphestIndexer' => 'applications/search/index/indexer/maniphest', - 'PhabricatorSearchMySQLExecutor' => 'applications/search/execute/mysql', 'PhabricatorSearchPhrictionIndexer' => 'applications/search/index/indexer/phriction', 'PhabricatorSearchQuery' => 'applications/search/storage/query', 'PhabricatorSearchRelationship' => 'applications/search/constants/relationship', @@ -909,6 +911,7 @@ phutil_register_library_map(array( 'PhabricatorDaemonTimelineConsoleController' => 'PhabricatorDaemonController', 'PhabricatorDaemonTimelineEventController' => 'PhabricatorDaemonController', 'PhabricatorDefaultFileStorageEngineSelector' => 'PhabricatorFileStorageEngineSelector', + 'PhabricatorDefaultSearchEngineSelector' => 'PhabricatorSearchEngineSelector', 'PhabricatorDirectoryCategory' => 'PhabricatorDirectoryDAO', 'PhabricatorDirectoryCategoryDeleteController' => 'PhabricatorDirectoryController', 'PhabricatorDirectoryCategoryEditController' => 'PhabricatorDirectoryController', @@ -1089,9 +1092,9 @@ phutil_register_library_map(array( 'PhabricatorSearchDocument' => 'PhabricatorSearchDAO', 'PhabricatorSearchDocumentField' => 'PhabricatorSearchDAO', 'PhabricatorSearchDocumentRelationship' => 'PhabricatorSearchDAO', + 'PhabricatorSearchEngineMySQL' => 'PhabricatorSearchEngine', 'PhabricatorSearchIndexController' => 'PhabricatorSearchBaseController', 'PhabricatorSearchManiphestIndexer' => 'PhabricatorSearchDocumentIndexer', - 'PhabricatorSearchMySQLExecutor' => 'PhabricatorSearchExecutor', 'PhabricatorSearchPhrictionIndexer' => 'PhabricatorSearchDocumentIndexer', 'PhabricatorSearchQuery' => 'PhabricatorSearchDAO', 'PhabricatorSearchResultView' => 'AphrontView', diff --git a/src/applications/diffusion/controller/commitlist/DiffusionCommitListController.php b/src/applications/diffusion/controller/commitlist/DiffusionCommitListController.php index 81f3a4b086..dfc136b9c2 100644 --- a/src/applications/diffusion/controller/commitlist/DiffusionCommitListController.php +++ b/src/applications/diffusion/controller/commitlist/DiffusionCommitListController.php @@ -67,8 +67,8 @@ class DiffusionCommitListController extends DiffusionController { ), phutil_escape_html($user->getUsername())); - $executor = new PhabricatorSearchMySQLExecutor(); - $results = $executor->executeSearch($query); + $engine = PhabricatorSearchEngineSelector::newSelector()->newEngine(); + $results = $engine->executeSearch($query); $results = $pager->sliceResults($results); $result_phids = ipull($results, 'phid'); $commit_table = self::createCommitTable($result_phids, $user); diff --git a/src/applications/diffusion/controller/commitlist/__init__.php b/src/applications/diffusion/controller/commitlist/__init__.php index a0f7a53626..edb00e7fdf 100644 --- a/src/applications/diffusion/controller/commitlist/__init__.php +++ b/src/applications/diffusion/controller/commitlist/__init__.php @@ -10,7 +10,7 @@ phutil_require_module('phabricator', 'applications/diffusion/controller/base'); phutil_require_module('phabricator', 'applications/people/storage/user'); phutil_require_module('phabricator', 'applications/phid/constants'); phutil_require_module('phabricator', 'applications/phid/handle/data'); -phutil_require_module('phabricator', 'applications/search/execute/mysql'); +phutil_require_module('phabricator', 'applications/search/selector/base'); phutil_require_module('phabricator', 'applications/search/storage/query'); phutil_require_module('phabricator', 'view/control/pager'); phutil_require_module('phabricator', 'view/control/table'); diff --git a/src/applications/search/controller/index/PhabricatorSearchIndexController.php b/src/applications/search/controller/index/PhabricatorSearchIndexController.php index b893b3c0dc..f6e08e7178 100644 --- a/src/applications/search/controller/index/PhabricatorSearchIndexController.php +++ b/src/applications/search/controller/index/PhabricatorSearchIndexController.php @@ -32,8 +32,8 @@ class PhabricatorSearchIndexController extends PhabricatorSearchBaseController { public function processRequest() { - $executor = new PhabricatorSearchMySQLExecutor(); - $document = $executor->reconstructDocument($this->phid); + $engine = PhabricatorSearchEngineSelector::newSelector()->newEngine(); + $document = $engine->reconstructDocument($this->phid); if (!$document) { return new Aphront404Response(); } diff --git a/src/applications/search/controller/index/__init__.php b/src/applications/search/controller/index/__init__.php index 6bb8ec7554..163079403b 100644 --- a/src/applications/search/controller/index/__init__.php +++ b/src/applications/search/controller/index/__init__.php @@ -9,7 +9,7 @@ phutil_require_module('phabricator', 'aphront/response/404'); phutil_require_module('phabricator', 'applications/phid/handle/data'); phutil_require_module('phabricator', 'applications/search/controller/base'); -phutil_require_module('phabricator', 'applications/search/execute/mysql'); +phutil_require_module('phabricator', 'applications/search/selector/base'); phutil_require_module('phabricator', 'view/control/table'); phutil_require_module('phabricator', 'view/layout/panel'); diff --git a/src/applications/search/controller/search/PhabricatorSearchController.php b/src/applications/search/controller/search/PhabricatorSearchController.php index 2b28c123a4..e70d7cffde 100644 --- a/src/applications/search/controller/search/PhabricatorSearchController.php +++ b/src/applications/search/controller/search/PhabricatorSearchController.php @@ -168,8 +168,8 @@ class PhabricatorSearchController extends PhabricatorSearchBaseController { $query->setParameter('limit', $limit + 1); $query->setParameter('offset', $pager->getOffset()); - $executor = new PhabricatorSearchMySQLExecutor(); - $results = $executor->executeSearch($query); + $engine = PhabricatorSearchEngineSelector::newSelector()->newEngine(); + $results = $engine->executeSearch($query); $results = ipull($results, 'phid'); $results = $pager->sliceResults($results); diff --git a/src/applications/search/controller/search/__init__.php b/src/applications/search/controller/search/__init__.php index 3d15da23cd..3754fb9f94 100644 --- a/src/applications/search/controller/search/__init__.php +++ b/src/applications/search/controller/search/__init__.php @@ -11,7 +11,7 @@ phutil_require_module('phabricator', 'aphront/response/redirect'); phutil_require_module('phabricator', 'applications/phid/constants'); phutil_require_module('phabricator', 'applications/phid/handle/data'); phutil_require_module('phabricator', 'applications/search/controller/base'); -phutil_require_module('phabricator', 'applications/search/execute/mysql'); +phutil_require_module('phabricator', 'applications/search/selector/base'); phutil_require_module('phabricator', 'applications/search/storage/query'); phutil_require_module('phabricator', 'applications/search/view/searchresult'); phutil_require_module('phabricator', 'infrastructure/celerity/api'); diff --git a/src/applications/search/engine/base/PhabricatorSearchEngine.php b/src/applications/search/engine/base/PhabricatorSearchEngine.php new file mode 100644 index 0000000000..57150e8b23 --- /dev/null +++ b/src/applications/search/engine/base/PhabricatorSearchEngine.php @@ -0,0 +1,57 @@ +getPHID(); + if (!$phid) { + throw new Exception("Document has no PHID!"); + } + + $store = new PhabricatorSearchDocument(); + $store->setPHID($doc->getPHID()); + $store->setDocumentType($doc->getDocumentType()); + $store->setDocumentTitle($doc->getDocumentTitle()); + $store->setDocumentCreated($doc->getDocumentCreated()); + $store->setDocumentModified($doc->getDocumentModified()); + $store->replace(); + + $conn_w = $store->establishConnection('w'); + + $field_dao = new PhabricatorSearchDocumentField(); + queryfx( + $conn_w, + 'DELETE FROM %T WHERE phid = %s', + $field_dao->getTableName(), + $phid); + foreach ($doc->getFieldData() as $field) { + list($ftype, $corpus, $aux_phid) = $field; + queryfx( + $conn_w, + 'INSERT INTO %T (phid, phidType, field, auxPHID, corpus) '. + ' VALUES (%s, %s, %s, %ns, %s)', + $field_dao->getTableName(), + $phid, + $doc->getDocumentType(), + $ftype, + $aux_phid, + $corpus); + } + + + $sql = array(); + foreach ($doc->getRelationshipData() as $relationship) { + list($rtype, $to_phid, $to_type, $time) = $relationship; + $sql[] = qsprintf( + $conn_w, + '(%s, %s, %s, %s, %d)', + $phid, + $to_phid, + $rtype, + $to_type, + $time); + } + + $rship_dao = new PhabricatorSearchDocumentRelationship(); + queryfx( + $conn_w, + 'DELETE FROM %T WHERE phid = %s', + $rship_dao->getTableName(), + $phid); + if ($sql) { + queryfx( + $conn_w, + 'INSERT INTO %T'. + ' (phid, relatedPHID, relation, relatedType, relatedTime) '. + ' VALUES %Q', + $rship_dao->getTableName(), + implode(', ', $sql)); + } + + } /** * Rebuild the PhabricatorSearchAbstractDocument that was used to index diff --git a/src/applications/search/execute/mysql/__init__.php b/src/applications/search/engine/mysql/__init__.php similarity index 83% rename from src/applications/search/execute/mysql/__init__.php rename to src/applications/search/engine/mysql/__init__.php index 24a7ac6fcc..094d7d60b8 100644 --- a/src/applications/search/execute/mysql/__init__.php +++ b/src/applications/search/engine/mysql/__init__.php @@ -7,7 +7,7 @@ phutil_require_module('phabricator', 'applications/search/constants/relationship'); -phutil_require_module('phabricator', 'applications/search/execute/base'); +phutil_require_module('phabricator', 'applications/search/engine/base'); phutil_require_module('phabricator', 'applications/search/index/abstractdocument'); phutil_require_module('phabricator', 'applications/search/storage/document/document'); phutil_require_module('phabricator', 'applications/search/storage/document/field'); @@ -18,4 +18,4 @@ phutil_require_module('phabricator', 'storage/queryfx'); phutil_require_module('phutil', 'utils'); -phutil_require_source('PhabricatorSearchMySQLExecutor.php'); +phutil_require_source('PhabricatorSearchEngineMySQL.php'); diff --git a/src/applications/search/index/indexer/base/PhabricatorSearchDocumentIndexer.php b/src/applications/search/index/indexer/base/PhabricatorSearchDocumentIndexer.php index 1069ee9e5b..e47130734a 100644 --- a/src/applications/search/index/indexer/base/PhabricatorSearchDocumentIndexer.php +++ b/src/applications/search/index/indexer/base/PhabricatorSearchDocumentIndexer.php @@ -16,4 +16,13 @@ * limitations under the License. */ -abstract class PhabricatorSearchDocumentIndexer { } +abstract class PhabricatorSearchDocumentIndexer { + + // TODO: Make this whole class tree concrete? + final protected static function reindexAbstractDocument( + PhabricatorSearchAbstractDocument $document) { + $engine = PhabricatorSearchEngineSelector::newSelector()->newEngine(); + $engine->reindexAbstractDocument($document); + } + +} diff --git a/src/applications/search/index/indexer/base/__init__.php b/src/applications/search/index/indexer/base/__init__.php index a31e434f43..aae0fb82e6 100644 --- a/src/applications/search/index/indexer/base/__init__.php +++ b/src/applications/search/index/indexer/base/__init__.php @@ -6,5 +6,7 @@ +phutil_require_module('phabricator', 'applications/search/selector/base'); + phutil_require_source('PhabricatorSearchDocumentIndexer.php'); diff --git a/src/applications/search/index/indexer/differential/PhabricatorSearchDifferentialIndexer.php b/src/applications/search/index/indexer/differential/PhabricatorSearchDifferentialIndexer.php index 7055ab9652..5c974b0a92 100644 --- a/src/applications/search/index/indexer/differential/PhabricatorSearchDifferentialIndexer.php +++ b/src/applications/search/index/indexer/differential/PhabricatorSearchDifferentialIndexer.php @@ -107,6 +107,6 @@ class PhabricatorSearchDifferentialIndexer $rev->getDateModified()); // Bogus timestamp. } - PhabricatorSearchDocument::reindexAbstractDocument($doc); + self::reindexAbstractDocument($doc); } } diff --git a/src/applications/search/index/indexer/differential/__init__.php b/src/applications/search/index/indexer/differential/__init__.php index bb280993f1..5853ef1671 100644 --- a/src/applications/search/index/indexer/differential/__init__.php +++ b/src/applications/search/index/indexer/differential/__init__.php @@ -14,7 +14,6 @@ phutil_require_module('phabricator', 'applications/search/constants/field'); phutil_require_module('phabricator', 'applications/search/constants/relationship'); phutil_require_module('phabricator', 'applications/search/index/abstractdocument'); phutil_require_module('phabricator', 'applications/search/index/indexer/base'); -phutil_require_module('phabricator', 'applications/search/storage/document/document'); phutil_require_module('phutil', 'utils'); diff --git a/src/applications/search/index/indexer/maniphest/PhabricatorSearchManiphestIndexer.php b/src/applications/search/index/indexer/maniphest/PhabricatorSearchManiphestIndexer.php index c3ac348f47..c9925762eb 100644 --- a/src/applications/search/index/indexer/maniphest/PhabricatorSearchManiphestIndexer.php +++ b/src/applications/search/index/indexer/maniphest/PhabricatorSearchManiphestIndexer.php @@ -127,6 +127,6 @@ class PhabricatorSearchManiphestIndexer $time); } - PhabricatorSearchDocument::reindexAbstractDocument($doc); + self::reindexAbstractDocument($doc); } } diff --git a/src/applications/search/index/indexer/maniphest/__init__.php b/src/applications/search/index/indexer/maniphest/__init__.php index df4bda6f78..940c01b08b 100644 --- a/src/applications/search/index/indexer/maniphest/__init__.php +++ b/src/applications/search/index/indexer/maniphest/__init__.php @@ -16,7 +16,6 @@ phutil_require_module('phabricator', 'applications/search/constants/field'); phutil_require_module('phabricator', 'applications/search/constants/relationship'); phutil_require_module('phabricator', 'applications/search/index/abstractdocument'); phutil_require_module('phabricator', 'applications/search/index/indexer/base'); -phutil_require_module('phabricator', 'applications/search/storage/document/document'); phutil_require_module('phutil', 'utils'); diff --git a/src/applications/search/index/indexer/phriction/PhabricatorSearchPhrictionIndexer.php b/src/applications/search/index/indexer/phriction/PhabricatorSearchPhrictionIndexer.php index c16c66f181..ae1b3575da 100644 --- a/src/applications/search/index/indexer/phriction/PhabricatorSearchPhrictionIndexer.php +++ b/src/applications/search/index/indexer/phriction/PhabricatorSearchPhrictionIndexer.php @@ -41,6 +41,6 @@ class PhabricatorSearchPhrictionIndexer PhabricatorPHIDConstants::PHID_TYPE_USER, $content->getDateCreated()); - PhabricatorSearchDocument::reindexAbstractDocument($doc); + self::reindexAbstractDocument($doc); } } diff --git a/src/applications/search/index/indexer/phriction/__init__.php b/src/applications/search/index/indexer/phriction/__init__.php index 3db665a13d..404ea7adbb 100644 --- a/src/applications/search/index/indexer/phriction/__init__.php +++ b/src/applications/search/index/indexer/phriction/__init__.php @@ -11,7 +11,6 @@ phutil_require_module('phabricator', 'applications/search/constants/field'); phutil_require_module('phabricator', 'applications/search/constants/relationship'); phutil_require_module('phabricator', 'applications/search/index/abstractdocument'); phutil_require_module('phabricator', 'applications/search/index/indexer/base'); -phutil_require_module('phabricator', 'applications/search/storage/document/document'); phutil_require_source('PhabricatorSearchPhrictionIndexer.php'); diff --git a/src/applications/search/index/indexer/repository/PhabricatorSearchCommitIndexer.php b/src/applications/search/index/indexer/repository/PhabricatorSearchCommitIndexer.php index e978555f99..e85005a69a 100644 --- a/src/applications/search/index/indexer/repository/PhabricatorSearchCommitIndexer.php +++ b/src/applications/search/index/indexer/repository/PhabricatorSearchCommitIndexer.php @@ -63,7 +63,7 @@ class PhabricatorSearchCommitIndexer PhabricatorPHIDConstants::PHID_TYPE_REPO, $date_created); - PhabricatorSearchDocument::reindexAbstractDocument($doc); + self::reindexAbstractDocument($doc); } } diff --git a/src/applications/search/index/indexer/repository/__init__.php b/src/applications/search/index/indexer/repository/__init__.php index e098b6527d..9d0b8d2e14 100644 --- a/src/applications/search/index/indexer/repository/__init__.php +++ b/src/applications/search/index/indexer/repository/__init__.php @@ -13,7 +13,6 @@ phutil_require_module('phabricator', 'applications/search/constants/field'); phutil_require_module('phabricator', 'applications/search/constants/relationship'); phutil_require_module('phabricator', 'applications/search/index/abstractdocument'); phutil_require_module('phabricator', 'applications/search/index/indexer/base'); -phutil_require_module('phabricator', 'applications/search/storage/document/document'); phutil_require_module('phutil', 'utils'); diff --git a/src/applications/search/index/indexer/user/PhabricatorSearchUserIndexer.php b/src/applications/search/index/indexer/user/PhabricatorSearchUserIndexer.php index c590a999cb..28178536e3 100644 --- a/src/applications/search/index/indexer/user/PhabricatorSearchUserIndexer.php +++ b/src/applications/search/index/indexer/user/PhabricatorSearchUserIndexer.php @@ -30,6 +30,6 @@ class PhabricatorSearchUserIndexer // TODO: Index the blurbs from their profile or something? Probably not // actually useful... - PhabricatorSearchDocument::reindexAbstractDocument($doc); + self::reindexAbstractDocument($doc); } } diff --git a/src/applications/search/index/indexer/user/__init__.php b/src/applications/search/index/indexer/user/__init__.php index d71b5877c8..f8b53d8704 100644 --- a/src/applications/search/index/indexer/user/__init__.php +++ b/src/applications/search/index/indexer/user/__init__.php @@ -9,7 +9,6 @@ phutil_require_module('phabricator', 'applications/phid/constants'); phutil_require_module('phabricator', 'applications/search/index/abstractdocument'); phutil_require_module('phabricator', 'applications/search/index/indexer/base'); -phutil_require_module('phabricator', 'applications/search/storage/document/document'); phutil_require_source('PhabricatorSearchUserIndexer.php'); diff --git a/src/applications/search/selector/base/PhabricatorSearchEngineSelector.php b/src/applications/search/selector/base/PhabricatorSearchEngineSelector.php new file mode 100644 index 0000000000..8f1a3ab875 --- /dev/null +++ b/src/applications/search/selector/base/PhabricatorSearchEngineSelector.php @@ -0,0 +1,32 @@ + + } + + abstract public function newEngine(); + + final public static function newSelector() { + $class = PhabricatorEnv::getEnvConfig('search.engine-selector'); + return newv($class, array()); + } + +} diff --git a/src/applications/search/selector/base/__init__.php b/src/applications/search/selector/base/__init__.php new file mode 100644 index 0000000000..6225135fb7 --- /dev/null +++ b/src/applications/search/selector/base/__init__.php @@ -0,0 +1,14 @@ +getPHID(); - if (!$phid) { - throw new Exception("Document has no PHID!"); - } - - $store = new PhabricatorSearchDocument(); - $store->setPHID($doc->getPHID()); - $store->setDocumentType($doc->getDocumentType()); - $store->setDocumentTitle($doc->getDocumentTitle()); - $store->setDocumentCreated($doc->getDocumentCreated()); - $store->setDocumentModified($doc->getDocumentModified()); - $store->replace(); - - $conn_w = $store->establishConnection('w'); - - $field_dao = new PhabricatorSearchDocumentField(); - queryfx( - $conn_w, - 'DELETE FROM %T WHERE phid = %s', - $field_dao->getTableName(), - $phid); - foreach ($doc->getFieldData() as $field) { - list($ftype, $corpus, $aux_phid) = $field; - queryfx( - $conn_w, - 'INSERT INTO %T (phid, phidType, field, auxPHID, corpus) '. - ' VALUES (%s, %s, %s, %ns, %s)', - $field_dao->getTableName(), - $phid, - $doc->getDocumentType(), - $ftype, - $aux_phid, - $corpus); - } - - - $sql = array(); - foreach ($doc->getRelationshipData() as $relationship) { - list($rtype, $to_phid, $to_type, $time) = $relationship; - $sql[] = qsprintf( - $conn_w, - '(%s, %s, %s, %s, %d)', - $phid, - $to_phid, - $rtype, - $to_type, - $time); - } - - $rship_dao = new PhabricatorSearchDocumentRelationship(); - queryfx( - $conn_w, - 'DELETE FROM %T WHERE phid = %s', - $rship_dao->getTableName(), - $phid); - if ($sql) { - queryfx( - $conn_w, - 'INSERT INTO %T'. - ' (phid, relatedPHID, relation, relatedType, relatedTime) '. - ' VALUES %Q', - $rship_dao->getTableName(), - implode(', ', $sql)); - } - - } - } diff --git a/src/applications/search/storage/document/document/__init__.php b/src/applications/search/storage/document/document/__init__.php index bae6063fde..a023bf220c 100644 --- a/src/applications/search/storage/document/document/__init__.php +++ b/src/applications/search/storage/document/document/__init__.php @@ -7,10 +7,6 @@ phutil_require_module('phabricator', 'applications/search/storage/base'); -phutil_require_module('phabricator', 'applications/search/storage/document/field'); -phutil_require_module('phabricator', 'applications/search/storage/document/relationship'); -phutil_require_module('phabricator', 'storage/qsprintf'); -phutil_require_module('phabricator', 'storage/queryfx'); phutil_require_source('PhabricatorSearchDocument.php');