Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-3214: If you use multiple fl entries rather than a comma separated list, all but the first entry can be ignored if you are using distributed search. SOLR-3256: Distributed search throws NPE when using fl=score

Mark Robert Miller7b3f632f32ae
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 12adecdec3b..a35bfc8d677 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -1,4 +1,4 @@
- Apache Solr Release Notes
+ Apache Solr Release Notes
Introduction
------------
@@ -353,7 +353,9 @@ Bug Fixes
* SOLR-3062: A join in the main query was not respecting any filters pushed
down to it via acceptDocs since LUCENE-1536. (Mike Hugo, yonik)
-
+
+* SOLR-3214: If you use multiple fl entries rather than a comma separated list, all but the first
+ entry can be ignored if you are using distributed search. (Tomas Fernandez Lobbe via Mark Miller)
Other Changes
----------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java b/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
index d991d2cb64b..c42e953a348 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
@@ -941,17 +941,10 @@ public class QueryComponent extends SearchComponent
// we already have the field sort values
sreq.params.remove(ResponseBuilder.FIELD_SORT_VALUES);
- // make sure that the id is returned for correlation.
- String fl = sreq.params.get(CommonParams.FL);
- if (fl != null) {
- fl = fl.trim();
- // currently, "score" is synonymous with "*,score" so
- // don't add "id" if the fl is empty or "score" or it would change the meaning.
- if (fl.length()!=0 && !"score".equals(fl) && !"*".equals(fl)) {
- sreq.params.set(CommonParams.FL, fl+','+uniqueField.getName());
- }
- }
-
+ if(!rb.rsp.getReturnFields().wantsField(uniqueField.getName())) {
+ sreq.params.add(CommonParams.FL, uniqueField.getName());
+ }
+
ArrayList<String> ids = new ArrayList<String>(shardDocs.size());
for (ShardDoc shardDoc : shardDocs) {
// TODO: depending on the type, we may need more tha a simple toString()?
@@ -979,6 +972,7 @@ public class QueryComponent extends SearchComponent
SolrDocumentList docs = (SolrDocumentList)srsp.getSolrResponse().getResponse().get("response");
String keyFieldName = rb.req.getSchema().getUniqueKeyField().getName();
+ boolean removeKeyField = !rb.rsp.getReturnFields().wantsField(keyFieldName);
for (SolrDocument doc : docs) {
Object id = doc.getFieldValue(keyFieldName);
@@ -987,6 +981,9 @@ public class QueryComponent extends SearchComponent
if (returnScores && sdoc.score != null) {
doc.setField("score", sdoc.score);
}
+ if(removeKeyField) {
+ doc.removeFields(keyFieldName);
+ }
rb._responseDocs.set(sdoc.positionInResponse, doc);
}
}
diff --git a/solr/core/src/test/org/apache/solr/TestDistributedSearch.java b/solr/core/src/test/org/apache/solr/TestDistributedSearch.java
index 88d3ab65869..aabd9c1dd03 100755
--- a/solr/core/src/test/org/apache/solr/TestDistributedSearch.java
+++ b/solr/core/src/test/org/apache/solr/TestDistributedSearch.java
@@ -204,6 +204,16 @@ public class TestDistributedSearch extends BaseDistributedSearchTestCase {
"facet.range.start",200,
"facet.range.gap",100,
"f."+tlong+".facet.range.end",900);
+
+ // variations of fl
+ query("q","*:*", "fl","score","sort",i1 + " desc");
+ query("q","*:*", "fl",i1 + ",score","sort",i1 + " desc");
+ query("q","*:*", "fl", i1, "fl","score","sort",i1 + " desc");
+ query("q","*:*", "fl", "id," + i1,"sort",i1 + " desc");
+ query("q","*:*", "fl", "id", "fl",i1,"sort",i1 + " desc");
+ query("q","*:*", "fl",i1, "fl", "id","sort",i1 + " desc");
+ query("q","*:*", "fl", "id", "fl",nint, "fl",tint,"sort",i1 + " desc");
+ query("q","*:*", "fl",nint, "fl", "id", "fl",tint,"sort",i1 + " desc");
stress=0; // turn off stress... we want to tex max combos in min time
for (int i=0; i<25*RANDOM_MULTIPLIER; i++) {