mikemccand commented on a change in pull request #638: LUCENE-8756: Fix MLT
like text with custom frequencies
URL: https://github.com/apache/lucene-solr/pull/638#discussion_r279685706
##########
File path:
lucene/queries/src/test/org/apache/lucene/queries/mlt/TestMoreLikeThis.java
##########
@@ -427,5 +438,70 @@ public void
testMultiFieldShouldReturnPerFieldBooleanQuery() throws Exception {
analyzer.close();
}
}
+
+ public void testCustomFrequecy() throws IOException {
+ // define an analyzer with delimited term frequency, e.g. "foo|2 bar|3"
+ Analyzer analyzer = new Analyzer() {
+
+ @Override
+ protected TokenStreamComponents createComponents(String fieldName) {
+ MockTokenizer tokenizer = new MockTokenizer(MockTokenizer.WHITESPACE,
false, 100);
+ MockTokenFilter filt = new MockTokenFilter(tokenizer,
MockTokenFilter.EMPTY_STOPSET);
+ return new TokenStreamComponents(tokenizer, foo(filt));
+ }
+
+ TokenStream foo(TokenStream input) {
+ return new TokenFilter(input) {
+
+ @Override
+ public boolean incrementToken() throws IOException {
+ final CharTermAttribute termAtt =
addAttribute(CharTermAttribute.class);
+ final TermFrequencyAttribute tfAtt =
addAttribute(TermFrequencyAttribute.class);
Review comment:
Normally `addAttribute` calls must happen at the `TokenFilter` construction
time -- I think the test only works because the `AttributeFactory` has already
added these attributes. Maybe move them up above?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]