Skip to content

Apache Lucene open-source search software

SOLR-1665: add distributed support

Grant Ingersoll34f0a6abe74c
diff --git a/solr/src/java/org/apache/solr/handler/component/DebugComponent.java b/solr/src/java/org/apache/solr/handler/component/DebugComponent.java
index 8ed4e2089a9..ed864cefc58 100644
--- a/solr/src/java/org/apache/solr/handler/component/DebugComponent.java
+++ b/solr/src/java/org/apache/solr/handler/component/DebugComponent.java
@@ -91,8 +91,16 @@ public class DebugComponent extends SearchComponent
// Turn on debug to get explain only when retrieving fields
if ((sreq.purpose & ShardRequest.PURPOSE_GET_FIELDS) != 0) {
- sreq.purpose |= ShardRequest.PURPOSE_GET_DEBUG;
+ sreq.purpose |= ShardRequest.PURPOSE_GET_DEBUG;
+ if (rb.isDebugAll()) {
sreq.params.set(CommonParams.DEBUG_QUERY, "true");
+ } else if (rb.isDebugQuery()){
+ sreq.params.set(CommonParams.DEBUG, CommonParams.QUERY);
+ } else if (rb.isDebugTimings()){
+ sreq.params.set(CommonParams.DEBUG, CommonParams.TIMING);
+ } else if (rb.isDebugResults()){
+ sreq.params.set(CommonParams.DEBUG, CommonParams.RESULTS);
+ }
} else {
sreq.params.set(CommonParams.DEBUG_QUERY, "false");
}
@@ -118,30 +126,35 @@ public class DebugComponent extends SearchComponent
NamedList sdebug = (NamedList)srsp.getSolrResponse().getResponse().get("debug");
info = (NamedList)merge(sdebug, info, excludeSet);
- NamedList sexplain = (NamedList)sdebug.get("explain");
-
- for (int i=0; i<sexplain.size(); i++) {
- String id = sexplain.getName(i);
- // TODO: lookup won't work for non-string ids... String vs Float
- ShardDoc sdoc = rb.resultIds.get(id);
- int idx = sdoc.positionInResponse;
- arr[idx] = new NamedList.NamedListEntry<Object>( id, sexplain.getVal(i));
+ if (rb.isDebugResults()) {
+ NamedList sexplain = (NamedList)sdebug.get("explain");
+ for (int i = 0; i < sexplain.size(); i++) {
+ String id = sexplain.getName(i);
+ // TODO: lookup won't work for non-string ids... String vs Float
+ ShardDoc sdoc = rb.resultIds.get(id);
+ int idx = sdoc.positionInResponse;
+ arr[idx] = new NamedList.NamedListEntry<Object>(id, sexplain.getVal(i));
+ }
}
}
}
- explain = HighlightComponent.removeNulls(new SimpleOrderedMap(arr));
+ if (rb.isDebugResults()) {
+ explain = SolrPluginUtils.removeNulls(new SimpleOrderedMap(arr));
+ }
if (info == null) {
info = new SimpleOrderedMap();
}
- int idx = info.indexOf("explain",0);
- if (idx>=0) {
- info.setVal(idx, explain);
- } else {
- info.add("explain", explain);
+ if (rb.isDebugResults()) {
+ int idx = info.indexOf("explain",0);
+ if (idx>=0) {
+ info.setVal(idx, explain);
+ } else {
+ info.add("explain", explain);
+ }
}
-
+
rb.setDebugInfo(info);
rb.rsp.add("debug", rb.getDebugInfo() );
}
diff --git a/solr/src/java/org/apache/solr/handler/component/HighlightComponent.java b/solr/src/java/org/apache/solr/handler/component/HighlightComponent.java
index d6168aa5823..2a050b5fa21 100644
--- a/solr/src/java/org/apache/solr/handler/component/HighlightComponent.java
+++ b/solr/src/java/org/apache/solr/handler/component/HighlightComponent.java
@@ -27,6 +27,7 @@ import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.highlight.SolrHighlighter;
import org.apache.solr.highlight.DefaultSolrHighlighter;
import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.util.SolrPluginUtils;
import org.apache.solr.util.plugin.PluginInfoInitialized;
import org.apache.solr.util.plugin.SolrCoreAware;
import org.apache.solr.core.PluginInfo;
@@ -36,7 +37,6 @@ import java.io.IOException;
import java.net.URL;
import java.util.Map;
import java.util.List;
-import java.util.Collections;
/**
* TODO!
@@ -165,27 +165,11 @@ public class HighlightComponent extends SearchComponent implements PluginInfoIni
}
// remove nulls in case not all docs were able to be retrieved
- rb.rsp.add("highlighting", removeNulls(new SimpleOrderedMap(arr)));
+ rb.rsp.add("highlighting", SolrPluginUtils.removeNulls(new SimpleOrderedMap(arr)));
}
}
- static NamedList removeNulls(NamedList nl) {
- for (int i=0; i<nl.size(); i++) {
- if (nl.getName(i)==null) {
- NamedList newList = nl instanceof SimpleOrderedMap ? new SimpleOrderedMap() : new NamedList();
- for (int j=0; j<nl.size(); j++) {
- String n = nl.getName(j);
- if (n != null) {
- newList.add(n, nl.getVal(j));
- }
- }
- return newList;
- }
- }
- return nl;
- }
-
public SolrHighlighter getHighlighter() {
return highlighter;
}
diff --git a/solr/src/java/org/apache/solr/handler/component/ResponseBuilder.java b/solr/src/java/org/apache/solr/handler/component/ResponseBuilder.java
index 1660f698b1f..c69e73c7009 100644
--- a/solr/src/java/org/apache/solr/handler/component/ResponseBuilder.java
+++ b/solr/src/java/org/apache/solr/handler/component/ResponseBuilder.java
@@ -160,6 +160,14 @@ public class ResponseBuilder {
public boolean isDebug() {
return debugQuery || debugTimings || debugResults;
}
+
+ /**
+ *
+ * @return true if all debugging options are on
+ */
+ public boolean isDebugAll(){
+ return debugQuery && debugTimings && debugResults;
+ }
public void setDebug(boolean dbg){
debugQuery = dbg;
diff --git a/solr/src/java/org/apache/solr/util/SolrPluginUtils.java b/solr/src/java/org/apache/solr/util/SolrPluginUtils.java
index ff54f6f209a..03507a0301c 100644
--- a/solr/src/java/org/apache/solr/util/SolrPluginUtils.java
+++ b/solr/src/java/org/apache/solr/util/SolrPluginUtils.java
@@ -726,6 +726,22 @@ public class SolrPluginUtils {
return s.toString().replace("\"","");
}
+ public static NamedList removeNulls(NamedList nl) {
+ for (int i=0; i<nl.size(); i++) {
+ if (nl.getName(i)==null) {
+ NamedList newList = nl instanceof SimpleOrderedMap ? new SimpleOrderedMap() : new NamedList();
+ for (int j=0; j<nl.size(); j++) {
+ String n = nl.getName(j);
+ if (n != null) {
+ newList.add(n, nl.getVal(j));
+ }
+ }
+ return newList;
+ }
+ }
+ return nl;
+ }
+
/**
* A subclass of SolrQueryParser that supports aliasing fields for
* constructing DisjunctionMaxQueries.
diff --git a/solr/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java b/solr/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java
new file mode 100644
index 00000000000..813905f05eb
--- /dev/null
+++ b/solr/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java
@@ -0,0 +1,52 @@
+package org.apache.solr.handler.component;
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.solr.BaseDistributedSearchTestCase;
+import org.apache.solr.common.params.CommonParams;
+
+
+/**
+ *
+ *
+ **/
+public class DistributedDebugComponentTest extends BaseDistributedSearchTestCase {
+
+ @Override
+ public void doTest() throws Exception {
+ index(id, "1", "title", "this is a title");
+ index(id, "2", "title", "this is another title.");
+ index(id, "3", "title", "Mary had a little lamb.");
+ commit();
+ handle.clear();
+ handle.put("QTime", SKIPVAL);
+ handle.put("timestamp", SKIPVAL);
+ handle.put("maxScore", SKIPVAL);
+ handle.put("time", SKIPVAL);
+
+ // we care only about the spellcheck results
+ handle.put("response", SKIP);
+ handle.put("explain", UNORDERED);
+ handle.put("debug", UNORDERED);
+ flags |= UNORDERED;
+ query("q", "*:*", CommonParams.DEBUG_QUERY, "true");
+ query("q", "*:*", CommonParams.DEBUG, CommonParams.TIMING);
+ query("q", "*:*", CommonParams.DEBUG, CommonParams.RESULTS);
+ query("q", "*:*", CommonParams.DEBUG, CommonParams.QUERY);
+
+ }
+}