mayya-sharipova commented on code in PR #14154: URL: https://github.com/apache/lucene/pull/14154#discussion_r1937606710
########## lucene/core/src/java/org/apache/lucene/analysis/AnalyzerWrapper.java: ########## @@ -151,4 +160,46 @@ protected final Reader initReaderForNormalization(String fieldName, Reader reade protected final AttributeFactory attributeFactory(String fieldName) { return getWrappedAnalyzer(fieldName).attributeFactory(fieldName); } + + public TokenStreamComponents getWrappedComponents(String fieldName) { + return wrappedComponentsPerField.get(fieldName); + } + + /** + * A {@link org.apache.lucene.analysis.Analyzer.ReuseStrategy} that checks the wrapped analyzer's + * strategy for reusability. If the wrapped analyzer's strategy returns null, components need to + * be re-created. + */ + public static final class UnwrappingReuseStrategy extends ReuseStrategy { + private final ReuseStrategy reuseStrategy; + + public UnwrappingReuseStrategy(ReuseStrategy reuseStrategy) { + this.reuseStrategy = reuseStrategy; + } + + @Override + public TokenStreamComponents getReusableComponents(Analyzer analyzer, String fieldName) { + if (analyzer instanceof AnalyzerWrapper wrapper) { + final Analyzer wrappedAnalyzer = wrapper.getWrappedAnalyzer(fieldName); + if (wrappedAnalyzer.getReuseStrategy().getReusableComponents(wrappedAnalyzer, fieldName) + == null) { + return null; + } + } + return reuseStrategy.getReusableComponents(analyzer, fieldName); + } + + @Override + public void setReusableComponents( + Analyzer analyzer, String fieldName, TokenStreamComponents components) { + reuseStrategy.setReusableComponents(analyzer, fieldName, components); + if (analyzer instanceof AnalyzerWrapper wrapper) { + final Analyzer wrappedAnalyzer = wrapper.getWrappedAnalyzer(fieldName); + wrappedAnalyzer + .getReuseStrategy() + .setReusableComponents( + wrappedAnalyzer, fieldName, wrapper.getWrappedComponents(fieldName)); + } + } Review Comment: Addressed in the last commit. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org