changeset 1474:13cbce740e1e

LowercaseAnalyzer
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 17 Apr 2020 21:53:09 -0600
parents 6c6ce14db6a8
children c7b86342857f
files src/goodjava/lucene/analysis/LowercaseAnalyzer.java src/luan/modules/lucene/Lucene.luan src/luan/modules/lucene/LuceneIndex.java
diffstat 3 files changed, 27 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
diff -r 6c6ce14db6a8 -r 13cbce740e1e src/goodjava/lucene/analysis/LowercaseAnalyzer.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/goodjava/lucene/analysis/LowercaseAnalyzer.java	Fri Apr 17 21:53:09 2020 -0600
@@ -0,0 +1,24 @@
+package goodjava.lucene.analysis;
+
+import java.io.Reader;
+import org.apache.lucene.util.Version;
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.Tokenizer;
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.core.KeywordTokenizer;
+import org.apache.lucene.analysis.core.LowerCaseFilter;
+
+
+public final class LowercaseAnalyzer extends Analyzer {
+	private final Version matchVersion;
+
+	public LowercaseAnalyzer(Version matchVersion) {
+		this.matchVersion = matchVersion;
+	}
+
+	protected TokenStreamComponents createComponents( String fieldName, Reader reader ) {
+		Tokenizer source = new KeywordTokenizer(reader);
+		TokenStream filter = new LowerCaseFilter(matchVersion,source);
+		return new TokenStreamComponents(source,filter);
+	}
+}
diff -r 6c6ce14db6a8 -r 13cbce740e1e src/luan/modules/lucene/Lucene.luan
--- a/src/luan/modules/lucene/Lucene.luan	Fri Apr 17 13:56:57 2020 -0600
+++ b/src/luan/modules/lucene/Lucene.luan	Fri Apr 17 21:53:09 2020 -0600
@@ -26,6 +26,7 @@
 Lucene.type = {
 	english = LuceneIndex.ENGLISH_FIELD_PARSER
 	string = LuceneIndex.STRING_FIELD_PARSER
+	lowercase = LuceneIndex.LOWERCASE_FIELD_PARSER
 	integer = NumberFieldParser.INT
 	long = NumberFieldParser.LONG
 	double = NumberFieldParser.DOUBLE
diff -r 6c6ce14db6a8 -r 13cbce740e1e src/luan/modules/lucene/LuceneIndex.java
--- a/src/luan/modules/lucene/LuceneIndex.java	Fri Apr 17 13:56:57 2020 -0600
+++ b/src/luan/modules/lucene/LuceneIndex.java	Fri Apr 17 21:53:09 2020 -0600
@@ -68,6 +68,7 @@
 import org.apache.lucene.search.highlight.SimpleSpanFragmenter;
 import org.apache.lucene.search.highlight.QueryScorer;
 import org.apache.lucene.search.highlight.TokenGroup;
+import goodjava.lucene.analysis.LowercaseAnalyzer;
 import goodjava.lucene.queryparser.GoodQueryParser;
 import goodjava.lucene.queryparser.FieldParser;
 import goodjava.lucene.queryparser.MultiFieldParser;
@@ -114,6 +115,7 @@
 	private static final Version luceneVersion = Version.LUCENE_4_9;
 	private static final String FLD_NEXT_ID = "nextId";
 	public static final StringFieldParser STRING_FIELD_PARSER = new StringFieldParser(new KeywordAnalyzer());
+	public static final StringFieldParser LOWERCASE_FIELD_PARSER = new StringFieldParser(new LowercaseAnalyzer(luceneVersion));
 	public static final StringFieldParser ENGLISH_FIELD_PARSER = new StringFieldParser(new EnglishAnalyzer(luceneVersion));
 
 	private final Object version;