Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CzechLuceneAnalyzer |
|
| 2.6666666666666665;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.LowerCaseTokenizer; | |
26 | import org.apache.lucene.analysis.StopFilter; | |
27 | import org.apache.lucene.analysis.TokenStream; | |
28 | import org.apache.lucene.analysis.cz.CzechAnalyzer; | |
29 | import org.apache.lucene.util.Version; | |
30 | ||
31 | /** | |
32 | * An Analyzer whose {@link TokenStream} is built from a | |
33 | * {@link LowerCaseTokenizer} filtered with {@link StopFilter} (optional). | |
34 | * Stemming not implemented yet | |
35 | * | |
36 | * @see gnu.lgpl.License The GNU Lesser General Public License for details. | |
37 | * @author Sijo Cherian | |
38 | * @author DM SMITH | |
39 | */ | |
40 | public class CzechLuceneAnalyzer extends AbstractBookAnalyzer { | |
41 | 0 | public CzechLuceneAnalyzer() { |
42 | 0 | stopSet = CzechAnalyzer.getDefaultStopSet(); |
43 | 0 | } |
44 | ||
45 | /* (non-Javadoc) | |
46 | * @see org.apache.lucene.analysis.Analyzer#tokenStream(java.lang.String, java.io.Reader) | |
47 | */ | |
48 | @Override | |
49 | public final TokenStream tokenStream(String fieldName, Reader reader) { | |
50 | 0 | TokenStream result = new LowerCaseTokenizer(reader); |
51 | ||
52 | 0 | if (doStopWords && stopSet != null) { |
53 | 0 | result = new StopFilter(false, result, stopSet); |
54 | } | |
55 | ||
56 | 0 | return result; |
57 | } | |
58 | ||
59 | /* (non-Javadoc) | |
60 | * @see org.apache.lucene.analysis.Analyzer#reusableTokenStream(java.lang.String, java.io.Reader) | |
61 | */ | |
62 | @Override | |
63 | public TokenStream reusableTokenStream(String fieldName, Reader reader) throws IOException { | |
64 | 0 | SavedStreams streams = (SavedStreams) getPreviousTokenStream(); |
65 | 0 | if (streams == null) { |
66 | 0 | streams = new SavedStreams(new LowerCaseTokenizer(reader)); |
67 | 0 | if (doStopWords && stopSet != null) { |
68 | 0 | streams.setResult(new StopFilter(StopFilter.getEnablePositionIncrementsVersionDefault(matchVersion), streams.getResult(), stopSet)); |
69 | } | |
70 | ||
71 | 0 | setPreviousTokenStream(streams); |
72 | } else { | |
73 | 0 | streams.getSource().reset(reader); |
74 | } | |
75 | 0 | return streams.getResult(); |
76 | } | |
77 | ||
78 | 0 | private final Version matchVersion = Version.LUCENE_29; |
79 | } |