mirror of https://github.com/apache/lucene.git
SOLR-12652: Clean up RealTimeGetComponent.toSolrDoc
(cherry picked from commit 97e7d8a3d7
)
This commit is contained in:
parent
9465763628
commit
15aa9dfb3d
|
@ -70,6 +70,8 @@ Other Changes
|
||||||
* SOLR-13467: Include the S2 Geometry lib to make it simpler to use prefixTree="s2" on a Geo3D spatial field.
|
* SOLR-13467: Include the S2 Geometry lib to make it simpler to use prefixTree="s2" on a Geo3D spatial field.
|
||||||
Improved documentation on Geo3D too. (David Smiley)
|
Improved documentation on Geo3D too. (David Smiley)
|
||||||
|
|
||||||
|
* SOLR-12562: Clean up RealTimeGetComponent.toSolrDoc (Erick Erickson)
|
||||||
|
|
||||||
================== 8.1.1 ==================
|
================== 8.1.1 ==================
|
||||||
|
|
||||||
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
|
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
|
||||||
|
|
|
@ -763,62 +763,34 @@ public class RealTimeGetComponent extends SearchComponent
|
||||||
SolrDocument out = new SolrDocument();
|
SolrDocument out = new SolrDocument();
|
||||||
for( IndexableField f : doc.getFields() ) {
|
for( IndexableField f : doc.getFields() ) {
|
||||||
// Make sure multivalued fields are represented as lists
|
// Make sure multivalued fields are represented as lists
|
||||||
Object existing = out.get(f.name());
|
|
||||||
if (existing == null) {
|
|
||||||
SchemaField sf = schema.getFieldOrNull(f.name());
|
SchemaField sf = schema.getFieldOrNull(f.name());
|
||||||
|
if (sf == null) {
|
||||||
|
// This is unexpected!
|
||||||
|
log.warn("schema.getFieldOrNull returned null {}, this is unexpected! ", f.name());
|
||||||
|
out.setField(f.name(), f.stringValue());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// don't return copyField targets
|
// don't return copyField targets
|
||||||
if (sf != null && schema.isCopyFieldTarget(sf)) continue;
|
if (schema.isCopyFieldTarget(sf)) continue;
|
||||||
|
|
||||||
if (sf != null && sf.multiValued()) {
|
if (out.get(f.name()) != null) {
|
||||||
|
out.addField(f.name(), sf.getType().toObject(f));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sf.multiValued()) {
|
||||||
List<Object> vals = new ArrayList<>();
|
List<Object> vals = new ArrayList<>();
|
||||||
if (f.fieldType().docValuesType() == DocValuesType.SORTED_NUMERIC) {
|
vals.add(sf.getType().toObject(f));
|
||||||
// SORTED_NUMERICS store sortable bits version of the value, need to retrieve the original
|
|
||||||
vals.add(sf.getType().toObject(f)); // (will materialize by side-effect)
|
|
||||||
} else {
|
|
||||||
vals.add( materialize(f) );
|
|
||||||
}
|
|
||||||
out.setField(f.name(), vals);
|
out.setField(f.name(), vals);
|
||||||
}
|
} else {
|
||||||
else{
|
out.setField(f.name(), sf.getType().toObject(f));
|
||||||
out.setField( f.name(), materialize(f) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
out.addField( f.name(), materialize(f) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Ensure we don't have {@link org.apache.lucene.document.LazyDocument.LazyField} or equivalent.
|
|
||||||
* It can pose problems if the searcher is about to be closed and we haven't fetched a value yet.
|
|
||||||
*/
|
|
||||||
private static IndexableField materialize(IndexableField in) {
|
|
||||||
if (in instanceof Field) { // already materialized
|
|
||||||
return in;
|
|
||||||
}
|
|
||||||
return new ClonedField(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ClonedField extends Field { // TODO Lucene Field has no copy constructor; maybe it should?
|
|
||||||
ClonedField(IndexableField in) {
|
|
||||||
super(in.name(), in.fieldType());
|
|
||||||
this.fieldsData = in.numericValue();
|
|
||||||
if (this.fieldsData == null) {
|
|
||||||
this.fieldsData = in.binaryValue();
|
|
||||||
if (this.fieldsData == null) {
|
|
||||||
this.fieldsData = in.stringValue();
|
|
||||||
if (this.fieldsData == null) {
|
|
||||||
// fallback:
|
|
||||||
assert false : in; // unexpected
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a SolrInputDocument to SolrDocument, using an IndexSchema instance.
|
* Converts a SolrInputDocument to SolrDocument, using an IndexSchema instance.
|
||||||
* @lucene.experimental
|
* @lucene.experimental
|
||||||
|
|
Loading…
Reference in New Issue