SOLR-2684: fix bug in BinaryResponseWriter introduced by SOLR-1566

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1152885 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2011-08-01 18:21:14 +00:00
parent 7e21a0c843
commit 47269b003f
4 changed files with 45 additions and 9 deletions

View File

@ -98,7 +98,9 @@ New Features
* SOLR-1566: Transforming documents in the ResponseWriters. This will allow
for more complex results in responses and open the door for function queries
as results. (ryan with patches from grant, noble, cmale, yonik, Jan Høydahl)
as results.
(ryan with patches from grant, noble, cmale, yonik, Jan Høydahl,
Arul Kalaipandian, hossman)
* SOLR-2396: Add CollationField, which is much more efficient than
the Solr 3.x CollationKeyFilterFactory, and also supports

View File

@ -89,12 +89,15 @@ public class BinaryResponseWriter implements BinaryQueryResponseWriter {
}
if (o instanceof SolrDocument) {
// Remove any fields that were not requested
// This typically happens when distributed search adds extra fields to an internal request
// Remove any fields that were not requested.
// This typically happens when distributed search adds
// extra fields to an internal request
SolrDocument doc = (SolrDocument)o;
for( String fname : doc.getFieldNames() ) {
if( !returnFields.wantsField( fname ) ) {
doc.removeFields( fname );
Iterator<Map.Entry<String, Object>> i = doc.iterator();
while ( i.hasNext() ) {
String fname = i.next().getKey();
if ( !returnFields.wantsField( fname ) ) {
i.remove();
}
}
return doc;

View File

@ -22,7 +22,10 @@ import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.JavaBinCodec;
import org.apache.solr.response.BinaryQueryResponseWriter;
import org.apache.solr.response.BinaryResponseWriter.Resolver;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.search.ReturnFields;
import org.apache.solr.util.AbstractSolrTestCase;
import java.io.ByteArrayInputStream;
@ -70,4 +73,31 @@ public class TestBinaryResponseWriter extends AbstractSolrTestCase {
req.close();
}
public void testResolverSolrDocumentPartialFields() throws Exception {
LocalSolrQueryRequest req = lrf.makeRequest("q", "*:*",
"fl", "id,xxx,ddd_s");
SolrDocument in = new SolrDocument();
in.addField("id", 345);
in.addField("aaa_s", "aaa");
in.addField("bbb_s", "bbb");
in.addField("ccc_s", "ccc");
in.addField("ddd_s", "ddd");
in.addField("eee_s", "eee");
Resolver r = new Resolver(req, new ReturnFields(req));
Object o = r.resolve(in, new JavaBinCodec());
assertNotNull("obj is null", o);
assertTrue("obj is not doc", o instanceof SolrDocument);
SolrDocument out = (SolrDocument) o;
assertTrue("id not found", out.getFieldNames().contains("id"));
assertTrue("ddd_s not found", out.getFieldNames().contains("ddd_s"));
assertEquals("Wrong number of fields found",
2, out.getFieldNames().size());
}
}

View File

@ -50,10 +50,11 @@ public class SolrDocument implements Map<String,Object>, Iterable<Map.Entry<Stri
}
/**
* @return a list of fields defined in this document
* @return a list of field names defined in this document - this Collection is directly backed by this SolrDocument.
* @see #keySet
*/
public Collection<String> getFieldNames() {
return _fields.keySet();
return this.keySet();
}
///////////////////////////////////////////////////////////////////
@ -73,7 +74,7 @@ public class SolrDocument implements Map<String,Object>, Iterable<Map.Entry<Stri
*/
public boolean removeFields(String name)
{
return _fields.remove( name ) != null;
return this.remove( name ) != null;
}
/**