You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by GitBox <gi...@apache.org> on 2019/04/30 09:55:57 UTC

[GitHub] [lucene-solr] mikemccand commented on a change in pull request #638: LUCENE-8756: Fix MLT like text with custom frequencies

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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org