]> source.dussan.org Git - sonarqube.git/commitdiff
DAOv.2 - Updated Core Analyzer for ES (required for sort, match and search in CodingR...
authorStephane Gamard <stephane.gamard@searchbox.com>
Wed, 28 May 2014 08:47:22 +0000 (10:47 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Wed, 28 May 2014 09:50:42 +0000 (11:50 +0200)
sonar-server/src/main/java/org/sonar/server/search/ESNode.java
sonar-server/src/test/java/org/sonar/server/search/ESNodeTest.java

index 0f69106a5fb5dfa110132ae249bd9892b355125b..b82aba120f742070af6ddc1251cf1a2983127e21 100644 (file)
@@ -130,16 +130,16 @@ public class ESNode implements Startable {
 
       .put("index.analysis.analyzer.sortable.type", "custom")
       .put("index.analysis.analyzer.sortable.tokenizer", "keyword")
-      .put("index.analysis.analyzer.sortable.filter", "lowercase")
+      .putArray("index.analysis.analyzer.sortable.filter", "trim","lowercase","truncate")
 
-      .put("index.analysis.analyzer.rule_name.type", "custom")
-      .put("index.analysis.analyzer.rule_name.tokenizer", "standard")
-      .putArray("index.analysis.analyzer.rule_name.filter", "lowercase", "rule_name_ngram")
+      .put("index.analysis.analyzer.string_gram.type", "custom")
+      .put("index.analysis.analyzer.string_gram.tokenizer", "whitespace")
+      .putArray("index.analysis.analyzer.string_gram.filter", "lowercase", "code_gram")
 
-      .put("index.analysis.filter.rule_name_ngram.type", "nGram")
-      .put("index.analysis.filter.rule_name_ngram.min_gram", 3)
-      .put("index.analysis.filter.rule_name_ngram.max_gram", 5)
-      .putArray("index.analysis.filter.rule_name_ngram.token_chars", "letter", "digit");
+      .put("index.analysis.filter.code_gram.type", "edgeNGram")
+      .put("index.analysis.filter.code_gram.min_gram", 2)
+      .put("index.analysis.filter.code_gram.max_gram", 15)
+      .putArray("index.analysis.filter.code_gram.token_chars", "letter", "digit", "punctuation", "symbol");
 
     initDirs(esSettings);
     initRestConsole(esSettings);
index 5f9b5a8ec489be1a9cae9b4c27fd7778a1368f87..5f990ed4faad15e433657aea573533f40ca3f232 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.server.search;
 import com.google.common.io.Resources;
 import org.apache.commons.io.FileUtils;
 import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
+import org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse;
 import org.elasticsearch.client.AdminClient;
 import org.elasticsearch.client.ClusterAdminClient;
 import org.elasticsearch.cluster.ClusterState;
@@ -102,11 +103,6 @@ public class ESNodeTest {
       .execute().actionGet();
     node.client().admin().cluster().prepareHealth("polop").setWaitForYellowStatus().get(TimeValue.timeValueMillis(1000));
 
-    // default "sortable" analyzer is defined for all indices
-    assertThat(node.client().admin().indices()
-      .prepareAnalyze("polop", "This Is A Wonderful Text").setAnalyzer("sortable").get()
-      .getTokens().get(0).getTerm()).isEqualTo("this is a wonderful text");
-
     // strict mapping is enforced
     try {
       node.client().prepareIndex("polop", "type1", "666").setSource(
@@ -117,6 +113,30 @@ public class ESNodeTest {
     }
   }
 
+  @Test
+  public void sortable_analyzer() throws Exception {
+    ESNode node = new ESNode(fs, new Settings());
+    node.start();
+
+    node.client().admin().indices().prepareCreate("polop")
+      .addMapping("type1", "{\"type1\": {\"properties\": {\"value\": {\"type\": \"string\"}}}}")
+      .execute().actionGet();
+    node.client().admin().cluster().prepareHealth("polop").setWaitForYellowStatus().get(TimeValue.timeValueMillis(1000));
+
+    // default "sortable" analyzer is defined for all indices
+    assertThat(node.client().admin().indices()
+      .prepareAnalyze("polop", "This Is A Wonderful Text").setAnalyzer("sortable").get()
+      .getTokens().get(0).getTerm()).isEqualTo("this is a ");
+
+    // default "sortable" analyzer is defined for all indices
+    AnalyzeResponse response = node.client().admin().indices()
+      .prepareAnalyze("polop", "he.llo w@rl#d").setAnalyzer("string_gram").get();
+
+    assertThat(response.getTokens()).hasSize(10);
+    assertThat(response.getTokens().get(0).getTerm()).isEqualTo("he");
+    assertThat(response.getTokens().get(7).getTerm()).isEqualTo("w@rl");
+  }
+
   @Test
   public void should_restore_status_on_startup() throws Exception {
     File zip = new File(Resources.getResource(getClass(), "ESNodeTest/data-es-clean.zip").toURI());