]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5007 - baseIndex supporting routing within ES 1.1.1
authorStephane Gamard <stephane.gamard@searchbox.com>
Fri, 16 May 2014 16:59:24 +0000 (18:59 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Mon, 19 May 2014 05:44:53 +0000 (07:44 +0200)
sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java
sonar-server/src/main/java/org/sonar/server/search/Result.java

index ed28ad4a5f8bfe83cb3f5066ae133522fe772a25..fa67533102f073d9f91eb4c234493561a96a6188 100644 (file)
@@ -148,10 +148,12 @@ public abstract class BaseIndex<D, E extends Dto<K>, K extends Serializable>
 
   public abstract D toDoc(GetResponse response);
 
-
   public D getByKey(K key) {
-    return toDoc(getClient().prepareGet(this.getIndexName(),
-      this.indexDefinition.getIndexType(), this.getKeyValue(key))
+    return toDoc(getClient().prepareGet()
+      .setType(this.getIndexType())
+      .setIndex(this.getIndexName())
+      .setId(this.getKeyValue(key))
+      .setRouting(this.getKeyValue(key))
       .get());
   }
 
@@ -203,7 +205,6 @@ public abstract class BaseIndex<D, E extends Dto<K>, K extends Serializable>
       .index(this.getIndexName())
       .id(this.getKeyValue(key))
       .type(this.getIndexType())).get();
-
   }
 
 
@@ -213,7 +214,7 @@ public abstract class BaseIndex<D, E extends Dto<K>, K extends Serializable>
       this.updateDocument(this.normalizer.normalizeOther(obj, key), key);
     } else {
       throw new IllegalStateException("Index " + this.getIndexName() +
-        " cannot execute INSERT for class: " + obj.getClass());
+        " cannot execute UPDATE for class: " + obj.getClass());
     }
   }
 
index 859c4a7e24a628372a1467a5b0c8818d472914ed..2b208a7a0c37eb0e0d96c9f5d0f872317b32ad5f 100644 (file)
@@ -28,30 +28,31 @@ import org.elasticsearch.search.facet.terms.TermsFacet;
 import javax.annotation.CheckForNull;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-public abstract class Result<K> {
+public  abstract class Result<K> {
 
   private final List<K> hits;
   private final Map<String, Collection<FacetValue>> facets;
-  private final long total;
-  private final long timeInMillis;
+  private long total;
+  private long timeInMillis;
+
 
   public Result(SearchResponse response) {
     this.hits = new ArrayList<K>();
+    this.facets = new HashMap<String, Collection<FacetValue>>();
+
     this.total = (int) response.getHits().totalHits();
     this.timeInMillis = response.getTookInMillis();
 
     for (SearchHit hit : response.getHits()) {
-      this.hits.add(getSearchResult(hit));
+      this.hits.add(getSearchResult(hit.getSource()));
     }
 
     if (response.getFacets() != null &&
       !response.getFacets().facets().isEmpty()) {
-      this.facets = new HashMap<String, Collection<FacetValue>>();
       for (Facet facet : response.getFacets().facets()) {
         TermsFacet termFacet = (TermsFacet) facet;
         List<FacetValue> facetValues = new ArrayList<FacetValue>();
@@ -61,19 +62,12 @@ public abstract class Result<K> {
         }
         this.facets.put(facet.getName(), facetValues);
       }
-    } else {
-      this.facets = Collections.emptyMap();
     }
   }
 
   /* Transform Methods */
-
   protected abstract K getSearchResult(Map<String, Object> fields);
 
-  protected K getSearchResult(SearchHit hit) {
-    return this.getSearchResult(hit.getSource());
-  }
-
   public List<K> getHits() {
     return hits;
   }
@@ -107,18 +101,6 @@ public abstract class Result<K> {
     return null;
   }
 
-  @CheckForNull
-  public Object getFacetTermValue(String facetName, String key) {
-    if (this.facets.containsKey(facetName)) {
-      for (FacetValue facetValue : facets.get(facetName)) {
-        if (facetValue.getKey().equals(key)) {
-          return facetValue.getValue();
-        }
-      }
-    }
-    return null;
-  }
-
   @Override
   public String toString() {
     return ReflectionToStringBuilder.toString(this);