Coverage Report - org.crosswire.jsword.index.lucene.analysis.ThaiLuceneAnalyzer
 
Classes in this File Line Coverage Branch Coverage Complexity
ThaiLuceneAnalyzer
0%
0/18
0%
0/10
2.667
 
 1  
 /**
 2  
  * Distribution License:
 3  
  * JSword is free software; you can redistribute it and/or modify it under
 4  
  * the terms of the GNU Lesser General Public License, version 2.1 or later
 5  
  * as published by the Free Software Foundation. This program is distributed
 6  
  * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 7  
  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 8  
  * See the GNU Lesser General Public License for more details.
 9  
  *
 10  
  * The License is available on the internet at:
 11  
  *      http://www.gnu.org/copyleft/lgpl.html
 12  
  * or by writing to:
 13  
  *      Free Software Foundation, Inc.
 14  
  *      59 Temple Place - Suite 330
 15  
  *      Boston, MA 02111-1307, USA
 16  
  *
 17  
  * © CrossWire Bible Society, 2007 - 2016
 18  
  *
 19  
  */
 20  
 package org.crosswire.jsword.index.lucene.analysis;
 21  
 
 22  
 import java.io.IOException;
 23  
 import java.io.Reader;
 24  
 
 25  
 import org.apache.lucene.analysis.StopFilter;
 26  
 import org.apache.lucene.analysis.TokenStream;
 27  
 import org.apache.lucene.analysis.standard.StandardTokenizer;
 28  
 import org.apache.lucene.analysis.th.ThaiWordFilter;
 29  
 import org.apache.lucene.util.Version;
 30  
 
 31  
 /**
 32  
  * Tokenization using ThaiWordFilter. It uses java.text.BreakIterator to break
 33  
  * words. Stemming: Not implemented
 34  
  * 
 35  
  * @see gnu.lgpl.License The GNU Lesser General Public License for details.
 36  
  * @author sijo cherian
 37  
  */
 38  
 public class ThaiLuceneAnalyzer extends AbstractBookAnalyzer {
 39  
 
 40  0
     public ThaiLuceneAnalyzer() {
 41  0
     }
 42  
 
 43  
     @Override
 44  
     public TokenStream tokenStream(String fieldName, Reader reader) {
 45  0
         TokenStream ts = new StandardTokenizer(matchVersion, reader);
 46  0
         ts = new ThaiWordFilter(ts);
 47  0
         if (doStopWords && stopSet != null) {
 48  0
             ts = new StopFilter(false, ts, stopSet);
 49  
         }
 50  0
         return ts;
 51  
     }
 52  
 
 53  
     /* (non-Javadoc)
 54  
      * @see org.apache.lucene.analysis.Analyzer#reusableTokenStream(java.lang.String, java.io.Reader)
 55  
      */
 56  
     @Override
 57  
     public TokenStream reusableTokenStream(String fieldName, Reader reader) throws IOException {
 58  0
         SavedStreams streams = (SavedStreams) getPreviousTokenStream();
 59  0
         if (streams == null) {
 60  0
             streams = new SavedStreams(new StandardTokenizer(matchVersion, reader));
 61  0
             streams.setResult(new ThaiWordFilter(streams.getResult()));
 62  
 
 63  0
             if (doStopWords && stopSet != null) {
 64  0
                 streams.setResult(new StopFilter(StopFilter.getEnablePositionIncrementsVersionDefault(matchVersion), streams.getResult(), stopSet));
 65  
             }
 66  
 
 67  0
             setPreviousTokenStream(streams);
 68  
         } else {
 69  0
             streams.getSource().reset(reader);
 70  0
             streams.getResult().reset(); // reset the ThaiWordFilter's state
 71  
         }
 72  0
         return streams.getResult();
 73  
     }
 74  
 
 75  0
     private final Version matchVersion = Version.LUCENE_29;
 76  
 }