From a632b220a84f809504948883e392bea2e064bccd Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 23 Jun 2011 13:31:20 -0700 Subject: [PATCH] Index users in search results. Summary: Add users to the search results. I need to follow this up with a patch to make the search results stop being terrible. I'll do that. Test Plan: Searched for users, ran "reindex_all_users.php" Reviewed By: jungejason Reviewers: tomo, jungejason, aran CC: aran, jungejason Differential Revision: 508 --- scripts/search/reindex_all_users.php | 32 +++++++++++++++++ src/__phutil_library_map__.php | 2 ++ .../method/conduit/connect/__init__.php | 1 - .../people/storage/user/PhabricatorUser.php | 6 +++- .../people/storage/user/__init__.php | 1 + .../user/PhabricatorSearchUserIndexer.php | 35 +++++++++++++++++++ .../search/index/indexer/user/__init__.php | 15 ++++++++ 7 files changed, 90 insertions(+), 2 deletions(-) create mode 100755 scripts/search/reindex_all_users.php create mode 100644 src/applications/search/index/indexer/user/PhabricatorSearchUserIndexer.php create mode 100644 src/applications/search/index/indexer/user/__init__.php diff --git a/scripts/search/reindex_all_users.php b/scripts/search/reindex_all_users.php new file mode 100755 index 0000000000..3c9f576404 --- /dev/null +++ b/scripts/search/reindex_all_users.php @@ -0,0 +1,32 @@ +#!/usr/bin/env php +loadAll(); +echo "Indexing ".count($users)." users"; +foreach ($users as $user) { + PhabricatorSearchUserIndexer::indexUser($user); + echo '.'; +} +echo "\n"; +echo "Done.\n"; + diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 6961bbe47a..aae4751e44 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -493,6 +493,7 @@ phutil_register_library_map(array( 'PhabricatorSearchQuery' => 'applications/search/storage/query', 'PhabricatorSearchRelationship' => 'applications/search/constants/relationship', 'PhabricatorSearchSelectController' => 'applications/search/controller/select', + 'PhabricatorSearchUserIndexer' => 'applications/search/index/indexer/user', 'PhabricatorSetup' => 'infrastructure/setup', 'PhabricatorStandardPageView' => 'view/page/standard', 'PhabricatorStatusController' => 'applications/status/base', @@ -951,6 +952,7 @@ phutil_register_library_map(array( 'PhabricatorSearchMySQLExecutor' => 'PhabricatorSearchExecutor', 'PhabricatorSearchQuery' => 'PhabricatorSearchDAO', 'PhabricatorSearchSelectController' => 'PhabricatorSearchController', + 'PhabricatorSearchUserIndexer' => 'PhabricatorSearchDocumentIndexer', 'PhabricatorStandardPageView' => 'AphrontPageView', 'PhabricatorStatusController' => 'PhabricatorController', 'PhabricatorTaskmasterDaemon' => 'PhabricatorDaemon', diff --git a/src/applications/conduit/method/conduit/connect/__init__.php b/src/applications/conduit/method/conduit/connect/__init__.php index 9b5ee7f26c..3c9a231761 100644 --- a/src/applications/conduit/method/conduit/connect/__init__.php +++ b/src/applications/conduit/method/conduit/connect/__init__.php @@ -10,7 +10,6 @@ phutil_require_module('phabricator', 'applications/conduit/method/base'); phutil_require_module('phabricator', 'applications/conduit/protocol/exception'); phutil_require_module('phabricator', 'applications/conduit/storage/connectionlog'); phutil_require_module('phabricator', 'applications/people/storage/user'); -phutil_require_module('phabricator', 'infrastructure/env'); phutil_require_module('phutil', 'utils'); diff --git a/src/applications/people/storage/user/PhabricatorUser.php b/src/applications/people/storage/user/PhabricatorUser.php index 5c087df013..d78301dd65 100644 --- a/src/applications/people/storage/user/PhabricatorUser.php +++ b/src/applications/people/storage/user/PhabricatorUser.php @@ -79,7 +79,11 @@ class PhabricatorUser extends PhabricatorUserDAO { if (!$this->conduitCertificate) { $this->conduitCertificate = $this->generateConduitCertificate(); } - return parent::save(); + $result = parent::save(); + + PhabricatorSearchUserIndexer::indexUser($this); + + return $result; } private function generateConduitCertificate() { diff --git a/src/applications/people/storage/user/__init__.php b/src/applications/people/storage/user/__init__.php index c75b225dbb..2f78f50a24 100644 --- a/src/applications/people/storage/user/__init__.php +++ b/src/applications/people/storage/user/__init__.php @@ -11,6 +11,7 @@ phutil_require_module('phabricator', 'applications/people/storage/log'); phutil_require_module('phabricator', 'applications/people/storage/preferences'); phutil_require_module('phabricator', 'applications/phid/constants'); phutil_require_module('phabricator', 'applications/phid/storage/phid'); +phutil_require_module('phabricator', 'applications/search/index/indexer/user'); phutil_require_module('phabricator', 'infrastructure/env'); phutil_require_module('phabricator', 'storage/queryfx'); diff --git a/src/applications/search/index/indexer/user/PhabricatorSearchUserIndexer.php b/src/applications/search/index/indexer/user/PhabricatorSearchUserIndexer.php new file mode 100644 index 0000000000..c590a999cb --- /dev/null +++ b/src/applications/search/index/indexer/user/PhabricatorSearchUserIndexer.php @@ -0,0 +1,35 @@ +setPHID($user->getPHID()); + $doc->setDocumentType(PhabricatorPHIDConstants::PHID_TYPE_USER); + $doc->setDocumentTitle($user->getUserName().'('.$user->getRealName().')'); + $doc->setDocumentCreated($user->getDateCreated()); + $doc->setDocumentModified($user->getDateModified()); + + // TODO: Index the blurbs from their profile or something? Probably not + // actually useful... + + PhabricatorSearchDocument::reindexAbstractDocument($doc); + } +} diff --git a/src/applications/search/index/indexer/user/__init__.php b/src/applications/search/index/indexer/user/__init__.php new file mode 100644 index 0000000000..d71b5877c8 --- /dev/null +++ b/src/applications/search/index/indexer/user/__init__.php @@ -0,0 +1,15 @@ +