mirror of https://github.com/apache/lucene.git
SOLR-8902: Make sure ReturnFields only returns the requested fields
This commit is contained in:
parent
39aaa108ac
commit
8254724bb1
|
@ -55,6 +55,9 @@ Bug Fixes
|
||||||
* SOLR-8857: HdfsUpdateLog does not use configured or new default number of version buckets and is
|
* SOLR-8857: HdfsUpdateLog does not use configured or new default number of version buckets and is
|
||||||
hard coded to 256. (Mark Miller, yonik, Gregory Chanan)
|
hard coded to 256. (Mark Miller, yonik, Gregory Chanan)
|
||||||
|
|
||||||
|
* SOLR-8902: Make sure ReturnFields only returns the requested fields from (fl=) evn when
|
||||||
|
DocumentTransformers ask for getExtraRequestFields() (ryan)
|
||||||
|
|
||||||
Optimizations
|
Optimizations
|
||||||
----------------------
|
----------------------
|
||||||
* SOLR-8722: Don't force a full ZkStateReader refresh on every Overseer operation.
|
* SOLR-8722: Don't force a full ZkStateReader refresh on every Overseer operation.
|
||||||
|
|
|
@ -72,8 +72,7 @@ public class BinaryResponseWriter implements BinaryQueryResponseWriter {
|
||||||
public static class Resolver implements JavaBinCodec.ObjectResolver , JavaBinCodec.WritableDocFields {
|
public static class Resolver implements JavaBinCodec.ObjectResolver , JavaBinCodec.WritableDocFields {
|
||||||
protected final SolrQueryRequest solrQueryRequest;
|
protected final SolrQueryRequest solrQueryRequest;
|
||||||
protected IndexSchema schema;
|
protected IndexSchema schema;
|
||||||
protected SolrIndexSearcher searcher; // TODO - this is never set? always null?
|
protected ReturnFields returnFields;
|
||||||
protected final ReturnFields returnFields;
|
|
||||||
|
|
||||||
public Resolver(SolrQueryRequest req, ReturnFields returnFields) {
|
public Resolver(SolrQueryRequest req, ReturnFields returnFields) {
|
||||||
solrQueryRequest = req;
|
solrQueryRequest = req;
|
||||||
|
@ -83,7 +82,13 @@ public class BinaryResponseWriter implements BinaryQueryResponseWriter {
|
||||||
@Override
|
@Override
|
||||||
public Object resolve(Object o, JavaBinCodec codec) throws IOException {
|
public Object resolve(Object o, JavaBinCodec codec) throws IOException {
|
||||||
if (o instanceof ResultContext) {
|
if (o instanceof ResultContext) {
|
||||||
writeResults((ResultContext) o, codec);
|
ReturnFields orig = returnFields;
|
||||||
|
ResultContext res = (ResultContext)o;
|
||||||
|
if(res.getReturnFields()!=null) {
|
||||||
|
returnFields = res.getReturnFields();
|
||||||
|
}
|
||||||
|
writeResults(res, codec);
|
||||||
|
returnFields = orig;
|
||||||
return null; // null means we completely handled it
|
return null; // null means we completely handled it
|
||||||
}
|
}
|
||||||
if (o instanceof DocList) {
|
if (o instanceof DocList) {
|
||||||
|
|
|
@ -51,6 +51,7 @@ public class SolrReturnFields extends ReturnFields {
|
||||||
private final List<String> globs = new ArrayList<>(1);
|
private final List<String> globs = new ArrayList<>(1);
|
||||||
|
|
||||||
// The lucene field names to request from the SolrIndexSearcher
|
// The lucene field names to request from the SolrIndexSearcher
|
||||||
|
// This *may* include fields that will not be in the final response
|
||||||
private final Set<String> fields = new HashSet<>();
|
private final Set<String> fields = new HashSet<>();
|
||||||
|
|
||||||
// Field names that are OK to include in the response.
|
// Field names that are OK to include in the response.
|
||||||
|
@ -130,17 +131,6 @@ public class SolrReturnFields extends ReturnFields {
|
||||||
augmenters.addTransformer( new RenameFieldTransformer( from, to, copy ) );
|
augmenters.addTransformer( new RenameFieldTransformer( from, to, copy ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !_wantsAllFields ) {
|
|
||||||
if( !globs.isEmpty() ) {
|
|
||||||
// TODO??? need to fill up the fields with matching field names in the index
|
|
||||||
// and add them to okFieldNames?
|
|
||||||
// maybe just get all fields?
|
|
||||||
// this would disable field selection optimization... i think thatis OK
|
|
||||||
fields.clear(); // this will get all fields, and use wantsField to limit
|
|
||||||
}
|
|
||||||
okFieldNames.addAll( fields );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( augmenters.size() == 1 ) {
|
if( augmenters.size() == 1 ) {
|
||||||
transformer = augmenters.getTransformer(0);
|
transformer = augmenters.getTransformer(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -264,6 +264,14 @@ public class ReturnFieldsTest extends SolrTestCaseJ4 {
|
||||||
assertFalse( rf.wantsField( "id" ) );
|
assertFalse( rf.wantsField( "id" ) );
|
||||||
assertFalse(rf.wantsAllFields());
|
assertFalse(rf.wantsAllFields());
|
||||||
assertNull(rf.getTransformer());
|
assertNull(rf.getTransformer());
|
||||||
|
|
||||||
|
// Don't return 'store_rpt' just because it is required by the transformer
|
||||||
|
rf = new SolrReturnFields( req("fl", "[geo f=store_rpt]") );
|
||||||
|
assertFalse( rf.wantsScore() );
|
||||||
|
assertTrue(rf.wantsField("[geo]"));
|
||||||
|
assertFalse( rf.wantsField( "store_rpt" ) );
|
||||||
|
assertFalse(rf.wantsAllFields());
|
||||||
|
assertNotNull(rf.getTransformer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue