Improve Search architecture
Summary:
The search indexing API has several problems right now:
- Always runs in-process.
- It would be nice to push this into the task queue for performance. However, the API currently passses an object all the way through (and some indexers depend on preloaded object attributes), so it can't be dumped into the task queue at any stage since we can't serialize it.
- Being able to use the task queue will also make rebuilding indexes faster.
- Instead, make the API phid-oriented.
- No uniform indexing API.
- Each "Editor" currently calls SomeCustomIndexer::indexThing(). This won't work with AbstractTransactions. The API is also just weird.
- Instead, provide a uniform API.
- No uniform CLI.
- We have `scripts/search/reindex_everything.php`, but it doesn't actually index everything. Each new document type needs to be separately added to it, leading to stuff like D3839. Third-party applications can't provide indexers.
- Instead, let indexers expose documents for indexing.
- Not application-oriented.
- All the indexers live in search/ right now, which isn't the right organization in an application-orietned view of the world.
- Instead, move indexers to applications and load them with SymbolLoader.
Test Plan:
- `bin/search index`
- Indexed one revision, one task.
- Indexed `--type TASK`, `--type DREV`, etc., for all types.
- Indexed `--all`.
- Added the word "saboteur" to a revision, task, wiki page, and question and then searched for it.
- Creating users is a pain; searched for a user after indexing.
- Creating commits is a pain; searched for a commit after indexing.
- Mocks aren't currently loadable in the result view, so their indexing is moot.
Reviewers: btrahan, vrana
Reviewed By: btrahan
CC: 20after4, aran
Maniphest Tasks: T1991, T2104
Differential Revision: https://secure.phabricator.com/D4261
2012-12-21 23:21:31 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group search
|
|
|
|
*/
|
|
|
|
final class PhabricatorSearchManagementIndexWorkflow
|
|
|
|
extends PhabricatorSearchManagementWorkflow {
|
|
|
|
|
|
|
|
protected function didConstruct() {
|
|
|
|
$this
|
|
|
|
->setName('index')
|
|
|
|
->setSynopsis('Build or rebuild search indexes.')
|
|
|
|
->setExamples(
|
|
|
|
"**index** D123\n".
|
|
|
|
"**index** --type DREV\n".
|
|
|
|
"**index** --all")
|
|
|
|
->setArguments(
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'name' => 'all',
|
|
|
|
'help' => 'Reindex all documents.',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'type',
|
|
|
|
'param' => 'TYPE',
|
|
|
|
'help' => 'PHID type to reindex, like "TASK" or "DREV".',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'background',
|
|
|
|
'help' => 'Instead of indexing in this process, queue tasks for '.
|
|
|
|
'the daemons. This is better if you are indexing a lot '.
|
|
|
|
'of stuff, but less helpful for debugging.',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'foreground',
|
|
|
|
'help' => 'Index in this process, even if there are many objects '.
|
|
|
|
'to index. This is helpful for debugging.',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'objects',
|
|
|
|
'wildcard' => true,
|
|
|
|
),
|
2013-02-19 22:33:10 +01:00
|
|
|
));
|
Improve Search architecture
Summary:
The search indexing API has several problems right now:
- Always runs in-process.
- It would be nice to push this into the task queue for performance. However, the API currently passses an object all the way through (and some indexers depend on preloaded object attributes), so it can't be dumped into the task queue at any stage since we can't serialize it.
- Being able to use the task queue will also make rebuilding indexes faster.
- Instead, make the API phid-oriented.
- No uniform indexing API.
- Each "Editor" currently calls SomeCustomIndexer::indexThing(). This won't work with AbstractTransactions. The API is also just weird.
- Instead, provide a uniform API.
- No uniform CLI.
- We have `scripts/search/reindex_everything.php`, but it doesn't actually index everything. Each new document type needs to be separately added to it, leading to stuff like D3839. Third-party applications can't provide indexers.
- Instead, let indexers expose documents for indexing.
- Not application-oriented.
- All the indexers live in search/ right now, which isn't the right organization in an application-orietned view of the world.
- Instead, move indexers to applications and load them with SymbolLoader.
Test Plan:
- `bin/search index`
- Indexed one revision, one task.
- Indexed `--type TASK`, `--type DREV`, etc., for all types.
- Indexed `--all`.
- Added the word "saboteur" to a revision, task, wiki page, and question and then searched for it.
- Creating users is a pain; searched for a user after indexing.
- Creating commits is a pain; searched for a commit after indexing.
- Mocks aren't currently loadable in the result view, so their indexing is moot.
Reviewers: btrahan, vrana
Reviewed By: btrahan
CC: 20after4, aran
Maniphest Tasks: T1991, T2104
Differential Revision: https://secure.phabricator.com/D4261
2012-12-21 23:21:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(PhutilArgumentParser $args) {
|
|
|
|
$console = PhutilConsole::getConsole();
|
|
|
|
|
|
|
|
$is_all = $args->getArg('all');
|
|
|
|
$is_type = $args->getArg('type');
|
|
|
|
|
|
|
|
$obj_names = $args->getArg('objects');
|
|
|
|
|
|
|
|
|
|
|
|
if ($obj_names && ($is_all || $is_type)) {
|
|
|
|
throw new PhutilArgumentUsageException(
|
|
|
|
"You can not name objects to index alongside the '--all' or '--type' ".
|
|
|
|
"flags.");
|
|
|
|
} else if (!$obj_names && !($is_all || $is_type)) {
|
|
|
|
throw new PhutilArgumentUsageException(
|
|
|
|
"Provide one of '--all', '--type' or a list of object names.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($obj_names) {
|
|
|
|
$phids = $this->loadPHIDsByNames($obj_names);
|
|
|
|
} else {
|
|
|
|
$phids = $this->loadPHIDsByTypes($is_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$phids) {
|
|
|
|
throw new PhutilArgumentUsageException(
|
|
|
|
"Nothing to index!");
|
|
|
|
}
|
|
|
|
|
|
|
|
$groups = phid_group_by_type($phids);
|
|
|
|
foreach ($groups as $group_type => $group) {
|
|
|
|
$console->writeOut(
|
|
|
|
pht(
|
|
|
|
"Indexing %d object(s) of type %s.",
|
|
|
|
count($group),
|
|
|
|
$group_type)."\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
$indexer = new PhabricatorSearchIndexer();
|
|
|
|
foreach ($phids as $phid) {
|
|
|
|
$indexer->indexDocumentByPHID($phid);
|
|
|
|
$console->writeOut(pht("Indexing '%s'...\n", $phid));
|
|
|
|
}
|
|
|
|
|
|
|
|
$console->writeOut("Done.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
private function loadPHIDsByNames(array $names) {
|
2013-07-21 22:11:39 +02:00
|
|
|
$query = id(new PhabricatorObjectQuery())
|
|
|
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
|
|
|
->withNames($names);
|
|
|
|
$query->execute();
|
|
|
|
$objects = $query->getNamedResults();
|
|
|
|
|
Improve Search architecture
Summary:
The search indexing API has several problems right now:
- Always runs in-process.
- It would be nice to push this into the task queue for performance. However, the API currently passses an object all the way through (and some indexers depend on preloaded object attributes), so it can't be dumped into the task queue at any stage since we can't serialize it.
- Being able to use the task queue will also make rebuilding indexes faster.
- Instead, make the API phid-oriented.
- No uniform indexing API.
- Each "Editor" currently calls SomeCustomIndexer::indexThing(). This won't work with AbstractTransactions. The API is also just weird.
- Instead, provide a uniform API.
- No uniform CLI.
- We have `scripts/search/reindex_everything.php`, but it doesn't actually index everything. Each new document type needs to be separately added to it, leading to stuff like D3839. Third-party applications can't provide indexers.
- Instead, let indexers expose documents for indexing.
- Not application-oriented.
- All the indexers live in search/ right now, which isn't the right organization in an application-orietned view of the world.
- Instead, move indexers to applications and load them with SymbolLoader.
Test Plan:
- `bin/search index`
- Indexed one revision, one task.
- Indexed `--type TASK`, `--type DREV`, etc., for all types.
- Indexed `--all`.
- Added the word "saboteur" to a revision, task, wiki page, and question and then searched for it.
- Creating users is a pain; searched for a user after indexing.
- Creating commits is a pain; searched for a commit after indexing.
- Mocks aren't currently loadable in the result view, so their indexing is moot.
Reviewers: btrahan, vrana
Reviewed By: btrahan
CC: 20after4, aran
Maniphest Tasks: T1991, T2104
Differential Revision: https://secure.phabricator.com/D4261
2012-12-21 23:21:31 +01:00
|
|
|
foreach ($names as $name) {
|
2013-07-21 22:11:39 +02:00
|
|
|
if (empty($objects[$name])) {
|
Improve Search architecture
Summary:
The search indexing API has several problems right now:
- Always runs in-process.
- It would be nice to push this into the task queue for performance. However, the API currently passses an object all the way through (and some indexers depend on preloaded object attributes), so it can't be dumped into the task queue at any stage since we can't serialize it.
- Being able to use the task queue will also make rebuilding indexes faster.
- Instead, make the API phid-oriented.
- No uniform indexing API.
- Each "Editor" currently calls SomeCustomIndexer::indexThing(). This won't work with AbstractTransactions. The API is also just weird.
- Instead, provide a uniform API.
- No uniform CLI.
- We have `scripts/search/reindex_everything.php`, but it doesn't actually index everything. Each new document type needs to be separately added to it, leading to stuff like D3839. Third-party applications can't provide indexers.
- Instead, let indexers expose documents for indexing.
- Not application-oriented.
- All the indexers live in search/ right now, which isn't the right organization in an application-orietned view of the world.
- Instead, move indexers to applications and load them with SymbolLoader.
Test Plan:
- `bin/search index`
- Indexed one revision, one task.
- Indexed `--type TASK`, `--type DREV`, etc., for all types.
- Indexed `--all`.
- Added the word "saboteur" to a revision, task, wiki page, and question and then searched for it.
- Creating users is a pain; searched for a user after indexing.
- Creating commits is a pain; searched for a commit after indexing.
- Mocks aren't currently loadable in the result view, so their indexing is moot.
Reviewers: btrahan, vrana
Reviewed By: btrahan
CC: 20after4, aran
Maniphest Tasks: T1991, T2104
Differential Revision: https://secure.phabricator.com/D4261
2012-12-21 23:21:31 +01:00
|
|
|
throw new PhutilArgumentUsageException(
|
|
|
|
"'{$name}' is not the name of a known object.");
|
|
|
|
}
|
|
|
|
}
|
2013-07-21 22:11:39 +02:00
|
|
|
|
|
|
|
return mpull($objects, 'getPHID');
|
Improve Search architecture
Summary:
The search indexing API has several problems right now:
- Always runs in-process.
- It would be nice to push this into the task queue for performance. However, the API currently passses an object all the way through (and some indexers depend on preloaded object attributes), so it can't be dumped into the task queue at any stage since we can't serialize it.
- Being able to use the task queue will also make rebuilding indexes faster.
- Instead, make the API phid-oriented.
- No uniform indexing API.
- Each "Editor" currently calls SomeCustomIndexer::indexThing(). This won't work with AbstractTransactions. The API is also just weird.
- Instead, provide a uniform API.
- No uniform CLI.
- We have `scripts/search/reindex_everything.php`, but it doesn't actually index everything. Each new document type needs to be separately added to it, leading to stuff like D3839. Third-party applications can't provide indexers.
- Instead, let indexers expose documents for indexing.
- Not application-oriented.
- All the indexers live in search/ right now, which isn't the right organization in an application-orietned view of the world.
- Instead, move indexers to applications and load them with SymbolLoader.
Test Plan:
- `bin/search index`
- Indexed one revision, one task.
- Indexed `--type TASK`, `--type DREV`, etc., for all types.
- Indexed `--all`.
- Added the word "saboteur" to a revision, task, wiki page, and question and then searched for it.
- Creating users is a pain; searched for a user after indexing.
- Creating commits is a pain; searched for a commit after indexing.
- Mocks aren't currently loadable in the result view, so their indexing is moot.
Reviewers: btrahan, vrana
Reviewed By: btrahan
CC: 20after4, aran
Maniphest Tasks: T1991, T2104
Differential Revision: https://secure.phabricator.com/D4261
2012-12-21 23:21:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function loadPHIDsByTypes($type) {
|
|
|
|
$indexer_symbols = id(new PhutilSymbolLoader())
|
|
|
|
->setAncestorClass('PhabricatorSearchDocumentIndexer')
|
|
|
|
->setConcreteOnly(true)
|
|
|
|
->setType('class')
|
|
|
|
->selectAndLoadSymbols();
|
|
|
|
|
|
|
|
$indexers = array();
|
|
|
|
foreach ($indexer_symbols as $symbol) {
|
|
|
|
$indexers[] = newv($symbol['name'], array());
|
|
|
|
}
|
|
|
|
|
|
|
|
$phids = array();
|
|
|
|
foreach ($indexers as $indexer) {
|
|
|
|
$indexer_phid = $indexer->getIndexableObject()->generatePHID();
|
|
|
|
$indexer_type = phid_get_type($indexer_phid);
|
|
|
|
|
2013-09-12 22:05:19 +02:00
|
|
|
if ($type && strcasecmp($indexer_type, $type)) {
|
Improve Search architecture
Summary:
The search indexing API has several problems right now:
- Always runs in-process.
- It would be nice to push this into the task queue for performance. However, the API currently passses an object all the way through (and some indexers depend on preloaded object attributes), so it can't be dumped into the task queue at any stage since we can't serialize it.
- Being able to use the task queue will also make rebuilding indexes faster.
- Instead, make the API phid-oriented.
- No uniform indexing API.
- Each "Editor" currently calls SomeCustomIndexer::indexThing(). This won't work with AbstractTransactions. The API is also just weird.
- Instead, provide a uniform API.
- No uniform CLI.
- We have `scripts/search/reindex_everything.php`, but it doesn't actually index everything. Each new document type needs to be separately added to it, leading to stuff like D3839. Third-party applications can't provide indexers.
- Instead, let indexers expose documents for indexing.
- Not application-oriented.
- All the indexers live in search/ right now, which isn't the right organization in an application-orietned view of the world.
- Instead, move indexers to applications and load them with SymbolLoader.
Test Plan:
- `bin/search index`
- Indexed one revision, one task.
- Indexed `--type TASK`, `--type DREV`, etc., for all types.
- Indexed `--all`.
- Added the word "saboteur" to a revision, task, wiki page, and question and then searched for it.
- Creating users is a pain; searched for a user after indexing.
- Creating commits is a pain; searched for a commit after indexing.
- Mocks aren't currently loadable in the result view, so their indexing is moot.
Reviewers: btrahan, vrana
Reviewed By: btrahan
CC: 20after4, aran
Maniphest Tasks: T1991, T2104
Differential Revision: https://secure.phabricator.com/D4261
2012-12-21 23:21:31 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$iterator = $indexer->getIndexIterator();
|
|
|
|
foreach ($iterator as $object) {
|
|
|
|
$phids[] = $object->getPHID();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $phids;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|