Skip to content

Commit 147d2e2

Browse files
author
epriestley
committed
Rought cut of search.
Summary: Botched this pretty badly in git so we'll see how much I broke. :/ Test Plan: Reviewers: CC:
1 parent fcc467f commit 147d2e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1183
-30
lines changed

scripts/__init_env__.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
require_once dirname(dirname(__FILE__)).'/conf/__init_conf__.php';
20+
21+
$env = getenv('PHABRICATOR_ENV');
22+
if (!$env) {
23+
echo "Define PHABRICATOR_ENV before running this script.\n";
24+
exit(1);
25+
}
26+
27+
$conf = phabricator_read_config_file($env);
28+
$conf['phabricator.env'] = $env;
29+
30+
phutil_require_module('phabricator', 'infrastructure/env');
31+
PhabricatorEnv::setEnvConfig($conf);

scripts/__init_script__.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,3 @@
3030
}
3131

3232
phutil_load_library(dirname(__FILE__).'/../src/');
33-
34-
require_once dirname(dirname(__FILE__)).'/conf/__init_conf__.php';

scripts/daemon/run_daemon.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,8 @@
1919

2020
$root = dirname(dirname(dirname(__FILE__)));
2121
require_once $root.'/scripts/__init_script__.php';
22+
require_once $root.'/scripts/__init_env__.php';
2223

23-
$env = getenv('PHABRICATOR_ENV');
24-
if (!$env) {
25-
echo "Define PHABRICATOR_ENV before running scripts.\n";
26-
exit(1);
27-
}
28-
29-
$conf = phabricator_read_config_file($env);
30-
$conf['phabricator.env'] = $env;
31-
32-
phutil_require_module('phabricator', 'infrastructure/env');
33-
PhabricatorEnv::setEnvConfig($conf);
3424
phutil_require_module('phutil', 'symbols');
3525

3626
PhutilSymbolLoader::loadClass('PhabricatorMetaMTADaemon');

scripts/search/reindex_everything.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
// TODO: Get rid of this script eventually, once this stuff is better-formalized
25+
// in Timeline consumers.
26+
27+
phutil_require_module('phutil', 'symbols');
28+
PhutilSymbolLoader::loadClass('DifferentialRevision');
29+
PhutilSymbolLoader::loadClass('PhabricatorSearchDifferentialIndexer');
30+
PhutilSymbolLoader::loadClass('ManiphestTask');
31+
PhutilSymbolLoader::loadClass('PhabricatorSearchManiphestIndexer');
32+
33+
echo "Loading revisions...\n";
34+
$revs = id(new DifferentialRevision())->loadAll();
35+
$count = count($revs);
36+
echo "Reindexing {$count} revisions";
37+
foreach ($revs as $rev) {
38+
PhabricatorSearchDifferentialIndexer::indexRevision($rev);
39+
echo '.';
40+
}
41+
echo "\n";
42+
43+
echo "Loading tasks...\n";
44+
$tasks = id(new ManiphestTask())->loadAll();
45+
$count = count($tasks);
46+
echo "Reindexing {$count} tasks";
47+
foreach ($tasks as $task) {
48+
PhabricatorSearchManiphestIndexer::indexTask($task);
49+
echo '.';
50+
}
51+
echo "\n";
52+
echo "Done.\n";
53+

src/__phutil_library_map__.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,21 @@
230230
'PhabricatorRepositoryGitHubNotification' => 'applications/repository/storage/githubnotification',
231231
'PhabricatorRepositoryGitHubPostReceiveController' => 'applications/repository/controller/github-post-receive',
232232
'PhabricatorRepositoryListController' => 'applications/repository/controller/list',
233+
'PhabricatorSearchAbstractDocument' => 'applications/search/index/abstractdocument',
234+
'PhabricatorSearchBaseController' => 'applications/search/controller/base',
235+
'PhabricatorSearchController' => 'applications/search/controller/search',
236+
'PhabricatorSearchDAO' => 'applications/search/storage/base',
237+
'PhabricatorSearchDifferentialIndexer' => 'applications/search/index/indexer/differential',
238+
'PhabricatorSearchDocument' => 'applications/search/storage/document/document',
239+
'PhabricatorSearchDocumentField' => 'applications/search/storage/document/field',
240+
'PhabricatorSearchDocumentIndexer' => 'applications/search/index/indexer/base',
241+
'PhabricatorSearchDocumentRelationship' => 'applications/search/storage/document/relationship',
242+
'PhabricatorSearchExecutor' => 'applications/search/execute/base',
243+
'PhabricatorSearchField' => 'applications/search/constants/field',
244+
'PhabricatorSearchManiphestIndexer' => 'applications/search/index/indexer/maniphest',
245+
'PhabricatorSearchMySQLExecutor' => 'applications/search/execute/mysql',
246+
'PhabricatorSearchQuery' => 'applications/search/storage/query',
247+
'PhabricatorSearchRelationship' => 'applications/search/constants/relationship',
233248
'PhabricatorStandardPageView' => 'view/page/standard',
234249
'PhabricatorTypeaheadCommonDatasourceController' => 'applications/typeahead/controller/common',
235250
'PhabricatorTypeaheadDatasourceController' => 'applications/typeahead/controller/base',
@@ -251,6 +266,7 @@
251266
'phabricator_format_relative_time' => 'view/utils',
252267
'phabricator_format_timestamp' => 'view/utils',
253268
'phabricator_format_units_generic' => 'view/utils',
269+
'phabricator_render_form' => 'infrastructure/javelin/markup',
254270
'qsprintf' => 'storage/qsprintf',
255271
'queryfx' => 'storage/queryfx',
256272
'queryfx_all' => 'storage/queryfx',
@@ -437,6 +453,16 @@
437453
'PhabricatorRepositoryGitHubNotification' => 'PhabricatorRepositoryDAO',
438454
'PhabricatorRepositoryGitHubPostReceiveController' => 'PhabricatorRepositoryController',
439455
'PhabricatorRepositoryListController' => 'PhabricatorController',
456+
'PhabricatorSearchBaseController' => 'PhabricatorController',
457+
'PhabricatorSearchController' => 'PhabricatorSearchBaseController',
458+
'PhabricatorSearchDAO' => 'PhabricatorLiskDAO',
459+
'PhabricatorSearchDifferentialIndexer' => 'PhabricatorSearchDocumentIndexer',
460+
'PhabricatorSearchDocument' => 'PhabricatorSearchDAO',
461+
'PhabricatorSearchDocumentField' => 'PhabricatorSearchDAO',
462+
'PhabricatorSearchDocumentRelationship' => 'PhabricatorSearchDAO',
463+
'PhabricatorSearchManiphestIndexer' => 'PhabricatorSearchDocumentIndexer',
464+
'PhabricatorSearchMySQLExecutor' => 'PhabricatorSearchExecutor',
465+
'PhabricatorSearchQuery' => 'PhabricatorSearchDAO',
440466
'PhabricatorStandardPageView' => 'AphrontPageView',
441467
'PhabricatorTypeaheadCommonDatasourceController' => 'PhabricatorTypeaheadDatasourceController',
442468
'PhabricatorTypeaheadDatasourceController' => 'PhabricatorController',

src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ public function getURIMap() {
155155
'edit/(?P<id>\d+)/$' => 'PhabricatorRepositoryEditController',
156156
'delete/(?P<id>\d+)/$' => 'PhabricatorRepositoryDeleteController',
157157
),
158+
159+
'/search/' => array(
160+
'$' => 'PhabricatorSearchController',
161+
'(?P<id>\d+)/$' => 'PhabricatorSearchController',
162+
),
158163
);
159164
}
160165

src/applications/differential/editor/revision/DifferentialRevisionEditor.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ public function save() {
415415
'actor' => $this->getActorPHID(),
416416
);
417417

418+
// TODO: When timelines get implemented, move indexing to them.
419+
PhabricatorSearchDifferentialIndexer::indexRevision($revision);
418420
// TODO
419421
// id(new ToolsTimelineEvent('difx', fb_json_encode($event)))->record();
420422

src/applications/differential/editor/revision/__init__.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
phutil_require_module('phabricator', 'applications/differential/storage/comment');
1313
phutil_require_module('phabricator', 'applications/differential/storage/revision');
1414
phutil_require_module('phabricator', 'applications/phid/handle/data');
15+
phutil_require_module('phabricator', 'applications/search/index/indexer/differential');
1516
phutil_require_module('phabricator', 'storage/qsprintf');
1617
phutil_require_module('phabricator', 'storage/queryfx');
1718

src/applications/maniphest/editor/transaction/ManiphestTransactionEditor.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ public function applyTransactions($task, array $transactions) {
9999
$email_cc,
100100
$task->getCCPHIDs());
101101

102+
// TODO: Do this offline via timeline
103+
PhabricatorSearchManiphestIndexer::indexTask($task);
104+
102105
$this->sendEmail($task, $transactions, $email_to, $email_cc);
103106
}
104107

src/applications/maniphest/editor/transaction/__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/maniphest/view/transactiondetail');
1212
phutil_require_module('phabricator', 'applications/metamta/storage/mail');
1313
phutil_require_module('phabricator', 'applications/phid/handle/data');
14+
phutil_require_module('phabricator', 'applications/search/index/indexer/maniphest');
1415
phutil_require_module('phabricator', 'infrastructure/env');
1516

1617
phutil_require_module('phutil', 'utils');

src/applications/phid/handle/data/PhabricatorObjectHandleData.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,52 @@ public function loadHandles() {
9696
$handles[$phid] = $handle;
9797
}
9898
break;
99+
case 'DREV':
100+
$class = 'DifferentialRevision';
101+
PhutilSymbolLoader::loadClass($class);
102+
$object = newv($class, array());
103+
104+
$revs = $object->loadAllWhere('phid in (%Ls)', $phids);
105+
$revs = mpull($revs, null, 'getPHID');
106+
107+
foreach ($phids as $phid) {
108+
$handle = new PhabricatorObjectHandle();
109+
$handle->setPHID($phid);
110+
if (empty($revs[$phid])) {
111+
$handle->setType(self::TYPE_UNKNOWN);
112+
$handle->setName('Unknown Revision');
113+
} else {
114+
$rev = $revs[$phid];
115+
$handle->setType($type);
116+
$handle->setName($rev->getTitle());
117+
$handle->setURI('/D'.$rev->getID());
118+
}
119+
$handles[$phid] = $handle;
120+
}
121+
break;
122+
case 'TASK':
123+
$class = 'ManiphestTask';
124+
PhutilSymbolLoader::loadClass($class);
125+
$object = newv($class, array());
126+
127+
$tasks = $object->loadAllWhere('phid in (%Ls)', $phids);
128+
$tasks = mpull($tasks, null, 'getPHID');
129+
130+
foreach ($phids as $phid) {
131+
$handle = new PhabricatorObjectHandle();
132+
$handle->setPHID($phid);
133+
if (empty($tasks[$phid])) {
134+
$handle->setType(self::TYPE_UNKNOWN);
135+
$handle->setName('Unknown Revision');
136+
} else {
137+
$task = $tasks[$phid];
138+
$handle->setType($type);
139+
$handle->setName($task->getTitle());
140+
$handle->setURI('/T'.$task->getID());
141+
}
142+
$handles[$phid] = $handle;
143+
}
144+
break;
99145
case 'FILE':
100146
$class = 'PhabricatorFile';
101147
PhutilSymbolLoader::loadClass($class);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
final class PhabricatorSearchField {
20+
21+
const FIELD_TITLE = 'titl';
22+
const FIELD_BODY = 'body';
23+
const FIELD_TEST_PLAN = 'tpln';
24+
25+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
/**
3+
* This file is automatically generated. Lint this module to rebuild it.
4+
* @generated
5+
*/
6+
7+
8+
9+
10+
phutil_require_source('PhabricatorSearchField.php');
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
final class PhabricatorSearchRelationship {
20+
21+
const RELATIONSHIP_AUTHOR = 'auth';
22+
const RELATIONSHIP_REVIEWER = 'revw';
23+
const RELATIONSHIP_SUBSCRIBER = 'subs';
24+
const RELATIONSHIP_COMMENTER = 'comm';
25+
26+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
/**
3+
* This file is automatically generated. Lint this module to rebuild it.
4+
* @generated
5+
*/
6+
7+
8+
9+
10+
phutil_require_source('PhabricatorSearchRelationship.php');
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
abstract class PhabricatorSearchBaseController extends PhabricatorController {
20+
21+
public function buildStandardPageResponse($view, array $data) {
22+
$page = $this->buildStandardPageView();
23+
24+
$page->setApplicationName('Search');
25+
$page->setBaseURI('/search/');
26+
$page->setTitle(idx($data, 'title'));
27+
$page->setGlyph("(?)");
28+
$page->appendChild($view);
29+
30+
$response = new AphrontWebpageResponse();
31+
return $response->setContent($page->render());
32+
}
33+
34+
}
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', 'aphront/response/webpage');
10+
phutil_require_module('phabricator', 'applications/base/controller/base');
11+
12+
phutil_require_module('phutil', 'utils');
13+
14+
15+
phutil_require_source('PhabricatorSearchBaseController.php');

0 commit comments

Comments
 (0)