diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 13b6ed7e3ff..14cd3ad3851 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -57,6 +57,8 @@ Upgrade Notes If a reporter configures the group="cluster" attribute then please also configure the 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 ---------------------- @@ -158,6 +160,8 @@ Other Changes * SOLR-11240: Raise UnInvertedField internal limit. (Toke Eskildsen) +* SOLR-11254: Add score-less (abstract) DocTransformer.transform method. (Christine Poerschke) + ================== 7.0.0 ================== Versions of Major Components diff --git a/solr/contrib/ltr/src/java/org/apache/solr/ltr/response/transform/LTRFeatureLoggerTransformerFactory.java b/solr/contrib/ltr/src/java/org/apache/solr/ltr/response/transform/LTRFeatureLoggerTransformerFactory.java index beb5ddf22ef..42d519ab1f9 100644 --- a/solr/contrib/ltr/src/java/org/apache/solr/ltr/response/transform/LTRFeatureLoggerTransformerFactory.java +++ b/solr/contrib/ltr/src/java/org/apache/solr/ltr/response/transform/LTRFeatureLoggerTransformerFactory.java @@ -255,13 +255,24 @@ public class LTRFeatureLoggerTransformerFactory extends TransformerFactory { @Override public void transform(SolrDocument doc, int docid, float score) 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); if (fv == null) { // FV for this document was not in the cache fv = featureLogger.makeFeatureVector( LTRRescorer.extractFeaturesInfo( modelWeight, docid, - (docsWereNotReranked ? new Float(score) : null), + (docsWereNotReranked ? score : null), leafContexts)); } diff --git a/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java b/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java index 85cb6f60dec..d60d268cc40 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java +++ b/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java @@ -265,7 +265,7 @@ public class RealTimeGetComponent extends SearchComponent throw new SolrException(ErrorCode.INVALID_STATE, "Expected ADD or UPDATE_INPLACE. Got: " + oper); } if (transformer!=null) { - transformer.transform(doc, -1, 0); // unknown docID + transformer.transform(doc, -1); // unknown docID } docList.add(doc); break; @@ -314,7 +314,7 @@ public class RealTimeGetComponent extends SearchComponent resultContext = new RTGResultContext(rsp.getReturnFields(), searcherInfo.getSearcher(), req); transformer.setContext(resultContext); } - transformer.transform(doc, docid, 0); + transformer.transform(doc, docid); } docList.add(doc); } diff --git a/solr/core/src/java/org/apache/solr/response/DocsStreamer.java b/solr/core/src/java/org/apache/solr/response/DocsStreamer.java index 40e0afc7484..714964583ef 100644 --- a/solr/core/src/java/org/apache/solr/response/DocsStreamer.java +++ b/solr/core/src/java/org/apache/solr/response/DocsStreamer.java @@ -167,7 +167,11 @@ public class DocsStreamer implements Iterator { if (transformer != null) { boolean doScore = rctx.wantsScores(); 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) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error applying transformer", e); } diff --git a/solr/core/src/java/org/apache/solr/response/transform/BaseEditorialTransformer.java b/solr/core/src/java/org/apache/solr/response/transform/BaseEditorialTransformer.java index bc5fb65d637..d646ee401c6 100644 --- a/solr/core/src/java/org/apache/solr/response/transform/BaseEditorialTransformer.java +++ b/solr/core/src/java/org/apache/solr/response/transform/BaseEditorialTransformer.java @@ -45,7 +45,7 @@ public abstract class BaseEditorialTransformer extends DocTransformer { } @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 Set ids = getIdSet(); if (ids != null && ids.isEmpty() == false) { diff --git a/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformerFactory.java b/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformerFactory.java index ff7c0614f3d..5e7b3c33a5b 100644 --- a/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformerFactory.java +++ b/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformerFactory.java @@ -123,7 +123,7 @@ class ChildDocTransformer extends DocTransformer { } @Override - public void transform(SolrDocument doc, int docid, float score) { + public void transform(SolrDocument doc, int docid) { FieldType idFt = idField.getType(); Object parentIdField = doc.getFirstValue(idField.getName()); diff --git a/solr/core/src/java/org/apache/solr/response/transform/DocIdAugmenterFactory.java b/solr/core/src/java/org/apache/solr/response/transform/DocIdAugmenterFactory.java index e95ac1e379e..219ca5d83e7 100644 --- a/solr/core/src/java/org/apache/solr/response/transform/DocIdAugmenterFactory.java +++ b/solr/core/src/java/org/apache/solr/response/transform/DocIdAugmenterFactory.java @@ -51,7 +51,7 @@ class DocIdAugmenter extends DocTransformer } @Override - public void transform(SolrDocument doc, int docid, float score) { + public void transform(SolrDocument doc, int docid) { assert -1 <= docid; doc.setField( name, docid ); } diff --git a/solr/core/src/java/org/apache/solr/response/transform/DocTransformer.java b/solr/core/src/java/org/apache/solr/response/transform/DocTransformer.java index 6111804ddbb..7665acd560f 100644 --- a/solr/core/src/java/org/apache/solr/response/transform/DocTransformer.java +++ b/solr/core/src/java/org/apache/solr/response/transform/DocTransformer.java @@ -73,13 +73,29 @@ public abstract class DocTransformer { * If implementations require a valid docId and index access, the {@link #needsSolrIndexSearcher} * method must return true * + * Default implementation calls {@link #transform(SolrDocument, int)}. + * * @param doc The document to alter * @param docid The Lucene internal doc id, or -1 in cases where the doc did not come from the index * @param score the score for this document * @throws IOException If there is a low-level I/O error. * @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 doc 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 diff --git a/solr/core/src/java/org/apache/solr/response/transform/DocTransformers.java b/solr/core/src/java/org/apache/solr/response/transform/DocTransformers.java index 7bb53ff2182..68a0b9f79f5 100644 --- a/solr/core/src/java/org/apache/solr/response/transform/DocTransformers.java +++ b/solr/core/src/java/org/apache/solr/response/transform/DocTransformers.java @@ -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 */ @Override public boolean needsSolrIndexSearcher() { diff --git a/solr/core/src/java/org/apache/solr/response/transform/ExplainAugmenterFactory.java b/solr/core/src/java/org/apache/solr/response/transform/ExplainAugmenterFactory.java index f9e1ec68cc7..c35ebd552ef 100644 --- a/solr/core/src/java/org/apache/solr/response/transform/ExplainAugmenterFactory.java +++ b/solr/core/src/java/org/apache/solr/response/transform/ExplainAugmenterFactory.java @@ -107,7 +107,7 @@ public class ExplainAugmenterFactory extends TransformerFactory } @Override - public void transform(SolrDocument doc, int docid, float score) { + public void transform(SolrDocument doc, int docid) { if( context != null && context.getQuery() != null ) { try { Explanation exp = context.getSearcher().explain(context.getQuery(), docid); diff --git a/solr/core/src/java/org/apache/solr/response/transform/GeoTransformerFactory.java b/solr/core/src/java/org/apache/solr/response/transform/GeoTransformerFactory.java index df54a1a317d..0b50254e52f 100644 --- a/solr/core/src/java/org/apache/solr/response/transform/GeoTransformerFactory.java +++ b/solr/core/src/java/org/apache/solr/response/transform/GeoTransformerFactory.java @@ -131,7 +131,7 @@ public class GeoTransformerFactory extends TransformerFactory } @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()); LeafReaderContext ctx = context.getSearcher().getTopReaderContext().leaves().get(leafOrd); ShapeValues values = shapes.getValues(ctx); @@ -148,7 +148,7 @@ public class GeoTransformerFactory extends TransformerFactory return new DocTransformer() { @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); if(val!=null) { updater.setValue(doc, val); diff --git a/solr/core/src/java/org/apache/solr/response/transform/RawValueTransformerFactory.java b/solr/core/src/java/org/apache/solr/response/transform/RawValueTransformerFactory.java index 1b5a8a638c0..5ec54272d56 100644 --- a/solr/core/src/java/org/apache/solr/response/transform/RawValueTransformerFactory.java +++ b/solr/core/src/java/org/apache/solr/response/transform/RawValueTransformerFactory.java @@ -107,7 +107,7 @@ public class RawValueTransformerFactory extends TransformerFactory } @Override - public void transform(SolrDocument doc, int docid, float score) { + public void transform(SolrDocument doc, int docid) { Object val = doc.remove(field); if(val==null) { return; diff --git a/solr/core/src/java/org/apache/solr/response/transform/RenameFieldTransformer.java b/solr/core/src/java/org/apache/solr/response/transform/RenameFieldTransformer.java index d96a541815c..41ac54f31dc 100644 --- a/solr/core/src/java/org/apache/solr/response/transform/RenameFieldTransformer.java +++ b/solr/core/src/java/org/apache/solr/response/transform/RenameFieldTransformer.java @@ -44,7 +44,7 @@ public class RenameFieldTransformer extends DocTransformer } @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 ); if( v != null ) { doc.setField(to, v); diff --git a/solr/core/src/java/org/apache/solr/response/transform/ScoreAugmenter.java b/solr/core/src/java/org/apache/solr/response/transform/ScoreAugmenter.java index 5a8205111e6..ef5550e8a69 100644 --- a/solr/core/src/java/org/apache/solr/response/transform/ScoreAugmenter.java +++ b/solr/core/src/java/org/apache/solr/response/transform/ScoreAugmenter.java @@ -44,4 +44,9 @@ public class ScoreAugmenter extends DocTransformer { doc.setField( name, score ); } } + + @Override + public void transform(SolrDocument doc, int docid) { + transform(doc, docid, 0.0f); + } } diff --git a/solr/core/src/java/org/apache/solr/response/transform/SubQueryAugmenterFactory.java b/solr/core/src/java/org/apache/solr/response/transform/SubQueryAugmenterFactory.java index 2d36e75f2c9..ad27404e087 100644 --- a/solr/core/src/java/org/apache/solr/response/transform/SubQueryAugmenterFactory.java +++ b/solr/core/src/java/org/apache/solr/response/transform/SubQueryAugmenterFactory.java @@ -321,7 +321,7 @@ class SubQueryAugmenter extends DocTransformer { public boolean needsSolrIndexSearcher() { return false; } @Override - public void transform(SolrDocument doc, int docid, float score) { + public void transform(SolrDocument doc, int docid) { final SolrParams docWithDeprefixed = SolrParams.wrapDefaults( new DocRowParams(doc, prefix, separator), baseSubParams); diff --git a/solr/core/src/java/org/apache/solr/response/transform/ValueAugmenterFactory.java b/solr/core/src/java/org/apache/solr/response/transform/ValueAugmenterFactory.java index e4edbdfdb7f..d85a302f507 100644 --- a/solr/core/src/java/org/apache/solr/response/transform/ValueAugmenterFactory.java +++ b/solr/core/src/java/org/apache/solr/response/transform/ValueAugmenterFactory.java @@ -96,7 +96,7 @@ class ValueAugmenter extends DocTransformer } @Override - public void transform(SolrDocument doc, int docid, float score) { + public void transform(SolrDocument doc, int docid) { doc.setField( name, value ); } } diff --git a/solr/core/src/java/org/apache/solr/response/transform/ValueSourceAugmenter.java b/solr/core/src/java/org/apache/solr/response/transform/ValueSourceAugmenter.java index c37dd80bfbf..8fcf56fc511 100644 --- a/solr/core/src/java/org/apache/solr/response/transform/ValueSourceAugmenter.java +++ b/solr/core/src/java/org/apache/solr/response/transform/ValueSourceAugmenter.java @@ -77,7 +77,7 @@ public class ValueSourceAugmenter extends DocTransformer List readerContexts; @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 try { diff --git a/solr/core/src/test/org/apache/solr/response/TestCustomDocTransformer.java b/solr/core/src/test/org/apache/solr/response/TestCustomDocTransformer.java index 5e1b13f55a0..ec263c422c1 100644 --- a/solr/core/src/test/org/apache/solr/response/TestCustomDocTransformer.java +++ b/solr/core/src/test/org/apache/solr/response/TestCustomDocTransformer.java @@ -105,7 +105,7 @@ public class TestCustomDocTransformer extends SolrTestCaseJ4 { * This transformer simply concatenates the values of multiple fields */ @Override - public void transform(SolrDocument doc, int docid, float score) throws IOException { + public void transform(SolrDocument doc, int docid) throws IOException { str.setLength(0); for(String s : extra) { String v = getAsString(s, doc);