Skip to content

Commit a632b22

Browse files
author
epriestley
committed
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
1 parent 9844bbb commit a632b22

File tree

7 files changed

+90
-2
lines changed

7 files changed

+90
-2
lines changed

scripts/search/reindex_all_users.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
/*
5+
* Copyright 2011 Facebook, Inc.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
$root = dirname(dirname(dirname(__FILE__)));
21+
require_once $root.'/scripts/__init_script__.php';
22+
require_once $root.'/scripts/__init_env__.php';
23+
24+
$users = id(new PhabricatorUser())->loadAll();
25+
echo "Indexing ".count($users)." users";
26+
foreach ($users as $user) {
27+
PhabricatorSearchUserIndexer::indexUser($user);
28+
echo '.';
29+
}
30+
echo "\n";
31+
echo "Done.\n";
32+

src/__phutil_library_map__.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@
493493
'PhabricatorSearchQuery' => 'applications/search/storage/query',
494494
'PhabricatorSearchRelationship' => 'applications/search/constants/relationship',
495495
'PhabricatorSearchSelectController' => 'applications/search/controller/select',
496+
'PhabricatorSearchUserIndexer' => 'applications/search/index/indexer/user',
496497
'PhabricatorSetup' => 'infrastructure/setup',
497498
'PhabricatorStandardPageView' => 'view/page/standard',
498499
'PhabricatorStatusController' => 'applications/status/base',
@@ -951,6 +952,7 @@
951952
'PhabricatorSearchMySQLExecutor' => 'PhabricatorSearchExecutor',
952953
'PhabricatorSearchQuery' => 'PhabricatorSearchDAO',
953954
'PhabricatorSearchSelectController' => 'PhabricatorSearchController',
955+
'PhabricatorSearchUserIndexer' => 'PhabricatorSearchDocumentIndexer',
954956
'PhabricatorStandardPageView' => 'AphrontPageView',
955957
'PhabricatorStatusController' => 'PhabricatorController',
956958
'PhabricatorTaskmasterDaemon' => 'PhabricatorDaemon',

src/applications/conduit/method/conduit/connect/__init__.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
phutil_require_module('phabricator', 'applications/conduit/protocol/exception');
1111
phutil_require_module('phabricator', 'applications/conduit/storage/connectionlog');
1212
phutil_require_module('phabricator', 'applications/people/storage/user');
13-
phutil_require_module('phabricator', 'infrastructure/env');
1413

1514
phutil_require_module('phutil', 'utils');
1615

src/applications/people/storage/user/PhabricatorUser.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ public function save() {
7979
if (!$this->conduitCertificate) {
8080
$this->conduitCertificate = $this->generateConduitCertificate();
8181
}
82-
return parent::save();
82+
$result = parent::save();
83+
84+
PhabricatorSearchUserIndexer::indexUser($this);
85+
86+
return $result;
8387
}
8488

8589
private function generateConduitCertificate() {

src/applications/people/storage/user/__init__.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
phutil_require_module('phabricator', 'applications/people/storage/preferences');
1212
phutil_require_module('phabricator', 'applications/phid/constants');
1313
phutil_require_module('phabricator', 'applications/phid/storage/phid');
14+
phutil_require_module('phabricator', 'applications/search/index/indexer/user');
1415
phutil_require_module('phabricator', 'infrastructure/env');
1516
phutil_require_module('phabricator', 'storage/queryfx');
1617

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2011 Facebook, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
class PhabricatorSearchUserIndexer
20+
extends PhabricatorSearchDocumentIndexer {
21+
22+
public static function indexUser(PhabricatorUser $user) {
23+
$doc = new PhabricatorSearchAbstractDocument();
24+
$doc->setPHID($user->getPHID());
25+
$doc->setDocumentType(PhabricatorPHIDConstants::PHID_TYPE_USER);
26+
$doc->setDocumentTitle($user->getUserName().'('.$user->getRealName().')');
27+
$doc->setDocumentCreated($user->getDateCreated());
28+
$doc->setDocumentModified($user->getDateModified());
29+
30+
// TODO: Index the blurbs from their profile or something? Probably not
31+
// actually useful...
32+
33+
PhabricatorSearchDocument::reindexAbstractDocument($doc);
34+
}
35+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* This file is automatically generated. Lint this module to rebuild it.
4+
* @generated
5+
*/
6+
7+
8+
9+
phutil_require_module('phabricator', 'applications/phid/constants');
10+
phutil_require_module('phabricator', 'applications/search/index/abstractdocument');
11+
phutil_require_module('phabricator', 'applications/search/index/indexer/base');
12+
phutil_require_module('phabricator', 'applications/search/storage/document/document');
13+
14+
15+
phutil_require_source('PhabricatorSearchUserIndexer.php');

0 commit comments

Comments
 (0)