1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 13:22:42 +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) ->setLocked(true)
->setDescription(pht('Elastic Search host.')) ->setDescription(pht('Elastic Search host.'))
->addExample('http://elastic.example.com:9200/', pht('Valid Setting')), ->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 { final class PhabricatorSearchEngineElastic extends PhabricatorSearchEngine {
private $uri; private $uri;
private $index;
private $timeout; private $timeout;
public function __construct($uri) { public function __construct($uri, $index) {
$this->uri = $uri; $this->uri = $uri;
$this->index = $index;
} }
public function setTimeout($timeout) { public function setTimeout($timeout) {
@ -51,7 +53,7 @@ final class PhabricatorSearchEngineElastic extends PhabricatorSearchEngine {
} }
$this->executeRequest( $this->executeRequest(
"/phabricator/{$type}/{$phid}/", "/{$type}/{$phid}/",
$spec, $spec,
$is_write = true); $is_write = true);
} }
@ -59,7 +61,7 @@ final class PhabricatorSearchEngineElastic extends PhabricatorSearchEngine {
public function reconstructDocument($phid) { public function reconstructDocument($phid) {
$type = phid_get_type($phid); $type = phid_get_type($phid);
$response = $this->executeRequest("/phabricator/{$type}/{$phid}", array()); $response = $this->executeRequest("/{$type}/{$phid}", array());
if (empty($response['exists'])) { if (empty($response['exists'])) {
return null; return null;
@ -210,10 +212,10 @@ final class PhabricatorSearchEngineElastic extends PhabricatorSearchEngine {
PhabricatorSearchApplicationSearchEngine::getIndexableDocumentTypes()); 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 // else in the index (for example if 'phabricator' is only an alias to
// some bigger index). // some bigger index). Use '/$types/_search' instead.
$uri = '/phabricator/'.implode(',', $types).'/_search'; $uri = '/'.implode(',', $types).'/_search';
try { try {
$response = $this->executeRequest($uri, $this->buildSpec($query)); $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) { private function executeRequest($path, array $data, $is_write = false) {
$uri = new PhutilURI($this->uri); $uri = new PhutilURI($this->uri);
$uri->setPath($this->index);
$uri->appendPath($path);
$data = json_encode($data); $data = json_encode($data);
$uri->setPath($path);
$future = new HTTPSFuture($uri, $data); $future = new HTTPSFuture($uri, $data);
if ($is_write) { if ($is_write) {
$future->setMethod('PUT'); $future->setMethod('PUT');

View file

@ -6,7 +6,8 @@ final class PhabricatorDefaultSearchEngineSelector
public function newEngine() { public function newEngine() {
$elastic_host = PhabricatorEnv::getEnvConfig('search.elastic.host'); $elastic_host = PhabricatorEnv::getEnvConfig('search.elastic.host');
if ($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(); return new PhabricatorSearchEngineMySQL();
} }