lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markrmil...@apache.org
Subject svn commit: r808982 - in /lucene/java/trunk/contrib/highlighter/src/java/org/apache/lucene/search/highlight: QueryScorer.java WeightedSpanTermExtractor.java
Date Fri, 28 Aug 2009 18:31:07 GMT
Author: markrmiller
Date: Fri Aug 28 18:31:07 2009
New Revision: 808982

URL: http://svn.apache.org/viewvc?rev=808982&view=rev
Log:
LUCENE-1871: Highlighter wraps caching token filters that are not CachingTokenFilter in CachingTokenFilter

Modified:
    lucene/java/trunk/contrib/highlighter/src/java/org/apache/lucene/search/highlight/QueryScorer.java
    lucene/java/trunk/contrib/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java

Modified: lucene/java/trunk/contrib/highlighter/src/java/org/apache/lucene/search/highlight/QueryScorer.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/highlighter/src/java/org/apache/lucene/search/highlight/QueryScorer.java?rev=808982&r1=808981&r2=808982&view=diff
==============================================================================
--- lucene/java/trunk/contrib/highlighter/src/java/org/apache/lucene/search/highlight/QueryScorer.java
(original)
+++ lucene/java/trunk/contrib/highlighter/src/java/org/apache/lucene/search/highlight/QueryScorer.java
Fri Aug 28 18:31:07 2009
@@ -23,6 +23,7 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.lucene.analysis.CachingTokenFilter;
 import org.apache.lucene.analysis.TokenStream;
 import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
 import org.apache.lucene.analysis.tokenattributes.TermAttribute;
@@ -52,6 +53,7 @@
   private String field;
   private IndexReader reader;
   private boolean skipInitExtractor;
+  private boolean wrapToCaching = true;
 
   /**
    * @param query Query to use for highlighting
@@ -209,6 +211,7 @@
         : new WeightedSpanTermExtractor(defaultField);
 
     qse.setExpandMultiTermQuery(expandMultiTermQuery);
+    qse.setWrapIfNotCachingTokenFilter(wrapToCaching);
     if (reader == null) {
       this.fieldWeightedSpanTerms = qse.getWeightedSpanTerms(query,
           tokenStream, field);
@@ -249,4 +252,17 @@
   public void setExpandMultiTermQuery(boolean expandMultiTermQuery) {
     this.expandMultiTermQuery = expandMultiTermQuery;
   }
+  
+  /**
+   * By default, {@link TokenStream}s that are not of the type
+   * {@link CachingTokenFilter} are wrapped in a {@link CachingTokenFilter} to
+   * ensure an efficient reset - if you are already using a different caching
+   * {@link TokenStream} impl and you don't want it to be wrapped, set this to
+   * false.
+   * 
+   * @param wrap
+   */
+  public void setWrapIfNotCachingTokenFilter(boolean wrap) {
+    this.wrapToCaching = wrap;
+  }
 }

Modified: lucene/java/trunk/contrib/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java?rev=808982&r1=808981&r2=808982&view=diff
==============================================================================
--- lucene/java/trunk/contrib/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java
(original)
+++ lucene/java/trunk/contrib/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java
Fri Aug 28 18:31:07 2009
@@ -64,6 +64,7 @@
   private String defaultField;
   private boolean expandMultiTermQuery;
   private boolean cachedTokenStream;
+  private boolean wrapToCaching = true;
 
   public WeightedSpanTermExtractor() {
   }
@@ -303,7 +304,7 @@
   }
 
   private IndexReader getReaderForField(String field) throws IOException {
-    if(!cachedTokenStream && !(tokenStream instanceof CachingTokenFilter)) {
+    if(wrapToCaching && !cachedTokenStream && !(tokenStream instanceof CachingTokenFilter))
{
       tokenStream = new CachingTokenFilter(tokenStream);
       cachedTokenStream = true;
     }
@@ -488,4 +489,17 @@
   public TokenStream getTokenStream() {
     return tokenStream;
   }
+  
+  /**
+   * By default, {@link TokenStream}s that are not of the type
+   * {@link CachingTokenFilter} are wrapped in a {@link CachingTokenFilter} to
+   * ensure an efficient reset - if you are already using a different caching
+   * {@link TokenStream} impl and you don't want it to be wrapped, set this to
+   * false.
+   * 
+   * @param wrap
+   */
+  public void setWrapIfNotCachingTokenFilter(boolean wrap) {
+    this.wrapToCaching = wrap;
+  }
 }



Mime
View raw message