1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 21:32:43 +01:00

Make it possible to configure Elasticsearch index name

Summary:
Similar to storage.default-namespace sometimes during development you'll want
to handle multiple indexes alongside one another. Rather than hardcoding the
/phabricator/ index make this exposed in new search.elastic.index setting,
defaulting to the existing "phabricator"

Test Plan:
Existing installations should be unaffected by this change. Changing the new
setting will result in new indexes being created when someone runs
`./bin/search index` again

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: 20after4, rush898, epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9798
This commit is contained in:
Chad Horohoe 2014-07-10 18:41:05 -07:00 committed by epriestley
parent 793eced32d
commit 66a3abe058
3 changed files with 16 additions and 9 deletions

View file

@ -32,6 +32,10 @@ final class PhabricatorSearchConfigOptions
->setLocked(true)
->setDescription(pht('Elastic Search host.'))
->addExample('http://elastic.example.com:9200/', pht('Valid Setting')),
$this->newOption('search.elastic.namespace', 'string', 'phabricator')
->setLocked(true)
->setDescription(pht('Elastic Search index.'))
->addExample('phabricator2', pht('Valid Setting')),
);
}

View file

@ -2,10 +2,12 @@
final class PhabricatorSearchEngineElastic extends PhabricatorSearchEngine {
private $uri;
private $index;
private $timeout;
public function __construct($uri) {
public function __construct($uri, $index) {
$this->uri = $uri;
$this->index = $index;
}
public function setTimeout($timeout) {
@ -51,7 +53,7 @@ final class PhabricatorSearchEngineElastic extends PhabricatorSearchEngine {
}
$this->executeRequest(
"/phabricator/{$type}/{$phid}/",
"/{$type}/{$phid}/",
$spec,
$is_write = true);
}
@ -59,7 +61,7 @@ final class PhabricatorSearchEngineElastic extends PhabricatorSearchEngine {
public function reconstructDocument($phid) {
$type = phid_get_type($phid);
$response = $this->executeRequest("/phabricator/{$type}/{$phid}", array());
$response = $this->executeRequest("/{$type}/{$phid}", array());
if (empty($response['exists'])) {
return null;
@ -210,10 +212,10 @@ final class PhabricatorSearchEngineElastic extends PhabricatorSearchEngine {
PhabricatorSearchApplicationSearchEngine::getIndexableDocumentTypes());
}
// Don't use '/phabricator/_search' for the case that there is something
// Don't use '/_search' for the case that there is something
// else in the index (for example if 'phabricator' is only an alias to
// some bigger index).
$uri = '/phabricator/'.implode(',', $types).'/_search';
// some bigger index). Use '/$types/_search' instead.
$uri = '/'.implode(',', $types).'/_search';
try {
$response = $this->executeRequest($uri, $this->buildSpec($query));
@ -238,10 +240,10 @@ final class PhabricatorSearchEngineElastic extends PhabricatorSearchEngine {
private function executeRequest($path, array $data, $is_write = false) {
$uri = new PhutilURI($this->uri);
$uri->setPath($this->index);
$uri->appendPath($path);
$data = json_encode($data);
$uri->setPath($path);
$future = new HTTPSFuture($uri, $data);
if ($is_write) {
$future->setMethod('PUT');

View file

@ -6,7 +6,8 @@ final class PhabricatorDefaultSearchEngineSelector
public function newEngine() {
$elastic_host = PhabricatorEnv::getEnvConfig('search.elastic.host');
if ($elastic_host) {
return new PhabricatorSearchEngineElastic($elastic_host);
$elastic_index = PhabricatorEnv::getEnvConfig('search.elastic.namespace');
return new PhabricatorSearchEngineElastic($elastic_host, $elastic_index);
}
return new PhabricatorSearchEngineMySQL();
}