You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2015/04/01 17:24:22 UTC
svn commit: r1670673 [2/2] - in /lucene/dev/branches/lucene6271: ./
dev-tools/ dev-tools/scripts/ lucene/ lucene/core/
lucene/core/src/java/org/apache/lucene/index/
lucene/core/src/java/org/apache/lucene/search/
lucene/core/src/test/org/apache/lucene/i...
Modified: lucene/dev/branches/lucene6271/solr/solrj/src/java/org/apache/solr/common/cloud/Slice.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6271/solr/solrj/src/java/org/apache/solr/common/cloud/Slice.java?rev=1670673&r1=1670672&r2=1670673&view=diff
==============================================================================
--- lucene/dev/branches/lucene6271/solr/solrj/src/java/org/apache/solr/common/cloud/Slice.java (original)
+++ lucene/dev/branches/lucene6271/solr/solrj/src/java/org/apache/solr/common/cloud/Slice.java Wed Apr 1 15:24:20 2015
@@ -23,28 +23,65 @@ import org.noggit.JSONWriter;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
+import java.util.Locale;
import java.util.Map;
/**
* A Slice contains immutable information about a logical shard (all replicas that share the same shard id).
*/
public class Slice extends ZkNodeProps {
- public static String REPLICAS = "replicas";
- public static String RANGE = "range";
- public static String STATE = "state";
- public static String LEADER = "leader"; // FUTURE: do we want to record the leader as a slice property in the JSON (as opposed to isLeader as a replica property?)
- public static String ACTIVE = "active";
- public static String INACTIVE = "inactive";
- public static String CONSTRUCTION = "construction";
- public static String RECOVERY = "recovery";
- public static String PARENT = "parent";
+
+ /** The slice's state. */
+ public enum State {
+
+ /** The default state of a slice. */
+ ACTIVE,
+
+ /**
+ * A slice is put in that state after it has been successfully split. See
+ * <a href="https://cwiki.apache.org/confluence/display/solr/Collections+API#CollectionsAPI-api3">
+ * the reference guide</a> for more details.
+ */
+ INACTIVE,
+
+ /**
+ * When a shard is split, the new sub-shards are put in that state while the
+ * split operation is in progress. A shard in that state still receives
+ * update requests from the parent shard leader, however does not participate
+ * in distributed search.
+ */
+ CONSTRUCTION,
+
+ /**
+ * Sub-shards of a split shard are put in that state, when they need to
+ * create replicas in order to meet the collection's replication factor. A
+ * shard in that state still receives update requests from the parent shard
+ * leader, however does not participate in distributed search.
+ */
+ RECOVERY;
+
+ @Override
+ public String toString() {
+ return super.toString().toLowerCase(Locale.ROOT);
+ }
+
+ /** Converts the state string to a State instance. */
+ public static State getState(String stateStr) {
+ return State.valueOf(stateStr.toUpperCase(Locale.ROOT));
+ }
+ }
+
+ public static final String REPLICAS = "replicas";
+ public static final String RANGE = "range";
+ public static final String LEADER = "leader"; // FUTURE: do we want to record the leader as a slice property in the JSON (as opposed to isLeader as a replica property?)
+ public static final String PARENT = "parent";
private final String name;
private final DocRouter.Range range;
private final Integer replicationFactor; // FUTURE: optional per-slice override of the collection replicationFactor
private final Map<String,Replica> replicas;
private final Replica leader;
- private final String state;
+ private final State state;
private final String parent;
private final Map<String, RoutingRule> routingRules;
@@ -58,11 +95,11 @@ public class Slice extends ZkNodeProps {
this.name = name;
Object rangeObj = propMap.get(RANGE);
- if (propMap.containsKey(STATE) && propMap.get(STATE) != null)
- this.state = (String) propMap.get(STATE);
- else {
- this.state = ACTIVE; //Default to ACTIVE
- propMap.put(STATE, this.state);
+ if (propMap.get(ZkStateReader.STATE_PROP) != null) {
+ this.state = State.getState((String) propMap.get(ZkStateReader.STATE_PROP));
+ } else {
+ this.state = State.ACTIVE; //Default to ACTIVE
+ propMap.put(ZkStateReader.STATE_PROP, state.toString());
}
DocRouter.Range tmpRange = null;
if (rangeObj instanceof DocRouter.Range) {
@@ -172,7 +209,7 @@ public class Slice extends ZkNodeProps {
return range;
}
- public String getState() {
+ public State getState() {
return state;
}
Modified: lucene/dev/branches/lucene6271/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6271/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java?rev=1670673&r1=1670672&r2=1670673&view=diff
==============================================================================
--- lucene/dev/branches/lucene6271/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java (original)
+++ lucene/dev/branches/lucene6271/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java Wed Apr 1 15:24:20 2015
@@ -46,6 +46,7 @@ import org.apache.solr.common.SolrInputD
import org.apache.solr.common.params.AnalysisParams;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.FacetParams;
+import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList;
import org.junit.Test;
import org.slf4j.Logger;
@@ -1587,6 +1588,41 @@ abstract public class SolrExampleTests e
}
@Test
+ public void testExpandComponent() throws IOException, SolrServerException {
+ SolrClient server = getSolrClient();
+ server.deleteByQuery("*:*");
+
+ ArrayList<SolrInputDocument> docs = new ArrayList<>();
+ docs.add( makeTestDoc("id","1", "term_s", "YYYY", "group_s", "group1", "test_ti", "5", "test_tl", "10", "test_tf", "2000", "type_s", "parent"));
+ docs.add( makeTestDoc("id","2", "term_s","YYYY", "group_s", "group1", "test_ti", "50", "test_tl", "100", "test_tf", "200", "type_s", "child"));
+ docs.add( makeTestDoc("id","3", "term_s", "YYYY", "test_ti", "5000", "test_tl", "100", "test_tf", "200"));
+ docs.add( makeTestDoc("id","4", "term_s", "YYYY", "test_ti", "500", "test_tl", "1000", "test_tf", "2000"));
+ docs.add( makeTestDoc("id","5", "term_s", "YYYY", "group_s", "group2", "test_ti", "4", "test_tl", "10", "test_tf", "2000", "type_s", "parent"));
+ docs.add( makeTestDoc("id","6", "term_s","YYYY", "group_s", "group2", "test_ti", "10", "test_tl", "100", "test_tf", "200", "type_s", "child"));
+ docs.add( makeTestDoc("id","7", "term_s", "YYYY", "group_s", "group1", "test_ti", "1", "test_tl", "100000", "test_tf", "2000", "type_s", "child"));
+ docs.add( makeTestDoc("id","8", "term_s","YYYY", "group_s", "group2", "test_ti", "2", "test_tl", "100000", "test_tf", "200", "type_s", "child"));
+
+ server.add(docs);
+ server.commit();
+
+ ModifiableSolrParams msParams = new ModifiableSolrParams();
+ msParams.add("q", "*:*");
+ msParams.add("fq", "{!collapse field=group_s}");
+ msParams.add("defType", "edismax");
+ msParams.add("bf", "field(test_ti)");
+ msParams.add("expand", "true");
+ QueryResponse resp = server.query(msParams);
+
+ Map<String, SolrDocumentList> expanded = resp.getExpandedResults();
+ assertEquals(2, expanded.size());
+ assertEquals("1", expanded.get("group1").get(0).get("id"));
+ assertEquals("7", expanded.get("group1").get(1).get("id"));
+ assertEquals("5", expanded.get("group2").get(0).get("id"));
+ assertEquals("8", expanded.get("group2").get(1).get("id"));
+
+ }
+
+ @Test
public void testFieldGlobbing() throws Exception {
SolrClient client = getSolrClient();