SOLR-11254: Add score-less (abstract) DocTransformer.transform method.

This commit is contained in:
Christine Poerschke 2017-08-23 12:31:56 +01:00
parent 6b8f98db93
commit 40fc36b87e
18 changed files with 64 additions and 17 deletions

View File

@ -57,6 +57,8 @@ Upgrade Notes
If a reporter configures the group="cluster" attribute then please also configure the If a reporter configures the group="cluster" attribute then please also configure the
class="org.apache.solr.metrics.reporters.solr.SolrClusterReporter" attribute. class="org.apache.solr.metrics.reporters.solr.SolrClusterReporter" attribute.
* SOLR-11254: the abstract DocTransformer class now has an abstract score-less transform method variant.
New Features New Features
---------------------- ----------------------
@ -158,6 +160,8 @@ Other Changes
* SOLR-11240: Raise UnInvertedField internal limit. (Toke Eskildsen) * SOLR-11240: Raise UnInvertedField internal limit. (Toke Eskildsen)
* SOLR-11254: Add score-less (abstract) DocTransformer.transform method. (Christine Poerschke)
================== 7.0.0 ================== ================== 7.0.0 ==================
Versions of Major Components Versions of Major Components

View File

@ -255,13 +255,24 @@ public class LTRFeatureLoggerTransformerFactory extends TransformerFactory {
@Override @Override
public void transform(SolrDocument doc, int docid, float score) public void transform(SolrDocument doc, int docid, float score)
throws IOException { throws IOException {
implTransform(doc, docid, new Float(score));
}
@Override
public void transform(SolrDocument doc, int docid)
throws IOException {
implTransform(doc, docid, 0.0f);
}
private void implTransform(SolrDocument doc, int docid, Float score)
throws IOException {
Object fv = featureLogger.getFeatureVector(docid, scoringQuery, searcher); Object fv = featureLogger.getFeatureVector(docid, scoringQuery, searcher);
if (fv == null) { // FV for this document was not in the cache if (fv == null) { // FV for this document was not in the cache
fv = featureLogger.makeFeatureVector( fv = featureLogger.makeFeatureVector(
LTRRescorer.extractFeaturesInfo( LTRRescorer.extractFeaturesInfo(
modelWeight, modelWeight,
docid, docid,
(docsWereNotReranked ? new Float(score) : null), (docsWereNotReranked ? score : null),
leafContexts)); leafContexts));
} }

View File

@ -265,7 +265,7 @@ public class RealTimeGetComponent extends SearchComponent
throw new SolrException(ErrorCode.INVALID_STATE, "Expected ADD or UPDATE_INPLACE. Got: " + oper); throw new SolrException(ErrorCode.INVALID_STATE, "Expected ADD or UPDATE_INPLACE. Got: " + oper);
} }
if (transformer!=null) { if (transformer!=null) {
transformer.transform(doc, -1, 0); // unknown docID transformer.transform(doc, -1); // unknown docID
} }
docList.add(doc); docList.add(doc);
break; break;
@ -314,7 +314,7 @@ public class RealTimeGetComponent extends SearchComponent
resultContext = new RTGResultContext(rsp.getReturnFields(), searcherInfo.getSearcher(), req); resultContext = new RTGResultContext(rsp.getReturnFields(), searcherInfo.getSearcher(), req);
transformer.setContext(resultContext); transformer.setContext(resultContext);
} }
transformer.transform(doc, docid, 0); transformer.transform(doc, docid);
} }
docList.add(doc); docList.add(doc);
} }

View File

@ -167,7 +167,11 @@ public class DocsStreamer implements Iterator<SolrDocument> {
if (transformer != null) { if (transformer != null) {
boolean doScore = rctx.wantsScores(); boolean doScore = rctx.wantsScores();
try { try {
transformer.transform(sdoc, id, doScore ? docIterator.score() : 0); if (doScore) {
transformer.transform(sdoc, id, docIterator.score());
} else {
transformer.transform(sdoc, id);
}
} catch (IOException e) { } catch (IOException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error applying transformer", e); throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error applying transformer", e);
} }

View File

@ -45,7 +45,7 @@ public abstract class BaseEditorialTransformer extends DocTransformer {
} }
@Override @Override
public void transform(SolrDocument doc, int docid, float score) { public void transform(SolrDocument doc, int docid) {
//this only gets added if QueryElevationParams.MARK_EXCLUDED is true //this only gets added if QueryElevationParams.MARK_EXCLUDED is true
Set<String> ids = getIdSet(); Set<String> ids = getIdSet();
if (ids != null && ids.isEmpty() == false) { if (ids != null && ids.isEmpty() == false) {

View File

@ -123,7 +123,7 @@ class ChildDocTransformer extends DocTransformer {
} }
@Override @Override
public void transform(SolrDocument doc, int docid, float score) { public void transform(SolrDocument doc, int docid) {
FieldType idFt = idField.getType(); FieldType idFt = idField.getType();
Object parentIdField = doc.getFirstValue(idField.getName()); Object parentIdField = doc.getFirstValue(idField.getName());

View File

@ -51,7 +51,7 @@ class DocIdAugmenter extends DocTransformer
} }
@Override @Override
public void transform(SolrDocument doc, int docid, float score) { public void transform(SolrDocument doc, int docid) {
assert -1 <= docid; assert -1 <= docid;
doc.setField( name, docid ); doc.setField( name, docid );
} }

View File

@ -73,13 +73,29 @@ public abstract class DocTransformer {
* If implementations require a valid docId and index access, the {@link #needsSolrIndexSearcher} * If implementations require a valid docId and index access, the {@link #needsSolrIndexSearcher}
* method must return true * method must return true
* *
* Default implementation calls {@link #transform(SolrDocument, int)}.
*
* @param doc The document to alter * @param doc The document to alter
* @param docid The Lucene internal doc id, or -1 in cases where the <code>doc</code> did not come from the index * @param docid The Lucene internal doc id, or -1 in cases where the <code>doc</code> did not come from the index
* @param score the score for this document * @param score the score for this document
* @throws IOException If there is a low-level I/O error. * @throws IOException If there is a low-level I/O error.
* @see #needsSolrIndexSearcher * @see #needsSolrIndexSearcher
*/ */
public abstract void transform(SolrDocument doc, int docid, float score) throws IOException; public void transform(SolrDocument doc, int docid, float score) throws IOException {
transform(doc, docid);
}
/**
* This is where implementations do the actual work.
* If implementations require a valid docId and index access, the {@link #needsSolrIndexSearcher}
* method must return true
*
* @param doc The document to alter
* @param docid The Lucene internal doc id, or -1 in cases where the <code>doc</code> did not come from the index
* @throws IOException If there is a low-level I/O error.
* @see #needsSolrIndexSearcher
*/
public abstract void transform(SolrDocument doc, int docid) throws IOException;
/** /**
* When a transformer needs access to fields that are not automatically derived from the * When a transformer needs access to fields that are not automatically derived from the

View File

@ -77,6 +77,13 @@ public class DocTransformers extends DocTransformer
} }
} }
@Override
public void transform(SolrDocument doc, int docid) throws IOException {
for( DocTransformer a : children ) {
a.transform( doc, docid);
}
}
/** Returns true if and only if at least 1 child transformer returns true */ /** Returns true if and only if at least 1 child transformer returns true */
@Override @Override
public boolean needsSolrIndexSearcher() { public boolean needsSolrIndexSearcher() {

View File

@ -107,7 +107,7 @@ public class ExplainAugmenterFactory extends TransformerFactory
} }
@Override @Override
public void transform(SolrDocument doc, int docid, float score) { public void transform(SolrDocument doc, int docid) {
if( context != null && context.getQuery() != null ) { if( context != null && context.getQuery() != null ) {
try { try {
Explanation exp = context.getSearcher().explain(context.getQuery(), docid); Explanation exp = context.getSearcher().explain(context.getQuery(), docid);

View File

@ -131,7 +131,7 @@ public class GeoTransformerFactory extends TransformerFactory
} }
@Override @Override
public void transform(SolrDocument doc, int docid, float score) throws IOException { public void transform(SolrDocument doc, int docid) throws IOException {
int leafOrd = ReaderUtil.subIndex(docid, context.getSearcher().getTopReaderContext().leaves()); int leafOrd = ReaderUtil.subIndex(docid, context.getSearcher().getTopReaderContext().leaves());
LeafReaderContext ctx = context.getSearcher().getTopReaderContext().leaves().get(leafOrd); LeafReaderContext ctx = context.getSearcher().getTopReaderContext().leaves().get(leafOrd);
ShapeValues values = shapes.getValues(ctx); ShapeValues values = shapes.getValues(ctx);
@ -148,7 +148,7 @@ public class GeoTransformerFactory extends TransformerFactory
return new DocTransformer() { return new DocTransformer() {
@Override @Override
public void transform(SolrDocument doc, int docid, float score) throws IOException { public void transform(SolrDocument doc, int docid) throws IOException {
Object val = doc.remove(updater.field); Object val = doc.remove(updater.field);
if(val!=null) { if(val!=null) {
updater.setValue(doc, val); updater.setValue(doc, val);

View File

@ -107,7 +107,7 @@ public class RawValueTransformerFactory extends TransformerFactory
} }
@Override @Override
public void transform(SolrDocument doc, int docid, float score) { public void transform(SolrDocument doc, int docid) {
Object val = doc.remove(field); Object val = doc.remove(field);
if(val==null) { if(val==null) {
return; return;

View File

@ -44,7 +44,7 @@ public class RenameFieldTransformer extends DocTransformer
} }
@Override @Override
public void transform(SolrDocument doc, int docid, float score) { public void transform(SolrDocument doc, int docid) {
Object v = (copy)?doc.get(from) : doc.remove( from ); Object v = (copy)?doc.get(from) : doc.remove( from );
if( v != null ) { if( v != null ) {
doc.setField(to, v); doc.setField(to, v);

View File

@ -44,4 +44,9 @@ public class ScoreAugmenter extends DocTransformer {
doc.setField( name, score ); doc.setField( name, score );
} }
} }
@Override
public void transform(SolrDocument doc, int docid) {
transform(doc, docid, 0.0f);
}
} }

View File

@ -321,7 +321,7 @@ class SubQueryAugmenter extends DocTransformer {
public boolean needsSolrIndexSearcher() { return false; } public boolean needsSolrIndexSearcher() { return false; }
@Override @Override
public void transform(SolrDocument doc, int docid, float score) { public void transform(SolrDocument doc, int docid) {
final SolrParams docWithDeprefixed = SolrParams.wrapDefaults( final SolrParams docWithDeprefixed = SolrParams.wrapDefaults(
new DocRowParams(doc, prefix, separator), baseSubParams); new DocRowParams(doc, prefix, separator), baseSubParams);

View File

@ -96,7 +96,7 @@ class ValueAugmenter extends DocTransformer
} }
@Override @Override
public void transform(SolrDocument doc, int docid, float score) { public void transform(SolrDocument doc, int docid) {
doc.setField( name, value ); doc.setField( name, value );
} }
} }

View File

@ -77,7 +77,7 @@ public class ValueSourceAugmenter extends DocTransformer
List<LeafReaderContext> readerContexts; List<LeafReaderContext> readerContexts;
@Override @Override
public void transform(SolrDocument doc, int docid, float score) { public void transform(SolrDocument doc, int docid) {
// This is only good for random-access functions // This is only good for random-access functions
try { try {

View File

@ -105,7 +105,7 @@ public class TestCustomDocTransformer extends SolrTestCaseJ4 {
* This transformer simply concatenates the values of multiple fields * This transformer simply concatenates the values of multiple fields
*/ */
@Override @Override
public void transform(SolrDocument doc, int docid, float score) throws IOException { public void transform(SolrDocument doc, int docid) throws IOException {
str.setLength(0); str.setLength(0);
for(String s : extra) { for(String s : extra) {
String v = getAsString(s, doc); String v = getAsString(s, doc);