mirror of https://github.com/apache/lucene.git
SOLR-1665: add distributed support
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@992128 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
cf162c2ed5
commit
34f0a6abe7
|
@ -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,28 +126,33 @@ 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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -161,6 +161,14 @@ public class ResponseBuilder {
|
|||
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;
|
||||
debugTimings = dbg;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue