Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15334432
D10955.id26307.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D10955.id26307.diff
View Options
diff --git a/src/applications/search/engine/PhabricatorSearchEngineElastic.php b/src/applications/search/engine/PhabricatorSearchEngineElastic.php
--- a/src/applications/search/engine/PhabricatorSearchEngineElastic.php
+++ b/src/applications/search/engine/PhabricatorSearchEngineElastic.php
@@ -238,6 +238,70 @@
return $phids;
}
+ public function indexExists() {
+ try {
+ (bool)$this->executeRequest('/_search/', array());
+ } catch (HTTPFutureHTTPResponseStatus $e) {
+ if ($e->getStatusCode() == 404) {
+ return false;
+ } else if ($e->getStatusCode() == 400) {
+ return true;
+ }
+ throw $e;
+ }
+ }
+
+ public function createIndex() {
+ $data = array(
+ 'settings' => array(
+ 'auto_expand_replicas' => '0-1',
+ 'analysis' => array(
+ 'filter' => array(
+ 'english_stop' => array(
+ 'type' => 'stop',
+ 'stopwords' => '_english_',
+ ),
+ 'english_possessive_stemmer' => array(
+ 'type' => 'stemmer',
+ 'language' => 'possessive_english',
+ ),
+ 'trigrams_filter' => array(
+ 'min_gram' => 3,
+ 'type' => 'ngram',
+ 'max_gram' => 3,
+ ),
+ 'english_stemmer' => array(
+ 'type' => 'stemmer',
+ 'language' => 'english',
+ ),
+ ),
+ 'analyzer' => array(
+ 'english_trigrams' => array(
+ 'type' => 'custom',
+ 'filter' => array(
+ 'english_possessive_stemmer',
+ 'lowercase',
+ 'english_stop',
+ 'english_stemmer',
+ 'trigrams_filter',
+ ),
+ 'tokenizer' => 'standard',
+ ),
+ ),
+ ),
+ ),
+ );
+
+ $types = array_keys(
+ PhabricatorSearchApplicationSearchEngine::getIndexableDocumentTypes());
+ foreach ($types as $type) {
+ $data['mappings'][$type]['properties']['field']['properties']['corpus'] =
+ array( 'type' => 'string', 'analyzer' => 'english_trigrams' );
+ }
+
+ $this->executeRequest('/', $data, true);
+ }
+
private function executeRequest($path, array $data, $is_write = false) {
$uri = new PhutilURI($this->uri);
$uri->setPath($this->index);
diff --git a/src/applications/search/management/PhabricatorSearchManagementIndexWorkflow.php b/src/applications/search/management/PhabricatorSearchManagementIndexWorkflow.php
--- a/src/applications/search/management/PhabricatorSearchManagementIndexWorkflow.php
+++ b/src/applications/search/management/PhabricatorSearchManagementIndexWorkflow.php
@@ -52,6 +52,19 @@
"Provide one of '--all', '--type' or a list of object names.");
}
+ if (PhabricatorDefaultSearchEngineSelector::shouldUseElasticSearch()) {
+ $engine = PhabricatorSearchEngineSelector::newSelector()->newEngine();
+ if (!$engine->indexExists()) {
+ $console->writeOut(
+ '%s',
+ pht('Index does not exist, creating...'));
+ $engine->createIndex();
+ $console->writeOut(
+ "%s\n",
+ pht('done.'));
+ }
+ }
+
if ($obj_names) {
$phids = $this->loadPHIDsByNames($obj_names);
} else {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Mar 9, 9:06 AM (3 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7387834
Default Alt Text
D10955.id26307.diff (3 KB)
Attached To
Mode
D10955: Properly create Elasticsearch index
Attached
Detach File
Event Timeline
Log In to Comment