Created
December 19, 2014 16:26
-
-
Save rnewson/1a68903974fc5d01edad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/src/main/java/com/github/rnewson/couchdb/lucene/util/Analyzers.java b/src/main/java/com/github/rnewson/couchdb/lucene/util/Analyzers.java | |
| index 6928967..697b289 100644 | |
| --- a/src/main/java/com/github/rnewson/couchdb/lucene/util/Analyzers.java | |
| +++ b/src/main/java/com/github/rnewson/couchdb/lucene/util/Analyzers.java | |
| @@ -167,10 +167,10 @@ public enum Analyzers { | |
| NGRAM { | |
| public Analyzer newAnalyzer(final String args) throws JSONException { | |
| final JSONObject json = new JSONObject(args == null ? "{}" : args); | |
| + final Analyzer parent = Analyzers.getAnalyzer(json.optString("parent", "standard")); | |
| int min = json.optInt("min", NGramTokenizer.DEFAULT_MIN_NGRAM_SIZE); | |
| int max = json.optInt("max", NGramTokenizer.DEFAULT_MAX_NGRAM_SIZE); | |
| - | |
| - return new NGramAnalyzer(min, max); | |
| + return new NGramAnalyzer(parent, min, max); | |
| } | |
| }; | |
| @@ -183,19 +183,22 @@ public enum Analyzers { | |
| } | |
| private static final class NGramAnalyzer extends Analyzer { | |
| - private int min; | |
| - private int max; | |
| + private final Analyzer parent; | |
| + private final int min; | |
| + private final int max; | |
| - public NGramAnalyzer(int min, int max) { | |
| + public NGramAnalyzer(final Analyzer parent, final int min, final int max) { | |
| + this.parent = parent; | |
| this.min = min; | |
| this.max = max; | |
| } | |
| @Override | |
| protected TokenStreamComponents createComponents(String fieldName, Reader reader) { | |
| - Tokenizer source = new NGramTokenizer(Constants.VERSION, reader, | |
| - this.min, this.max); | |
| - return new TokenStreamComponents(source); | |
| + final TokenStreamComponents delegate = parent.createComponents(fieldName, reader); | |
| + return new TokenStreamComponents(delegate.getTokenizer(), | |
| + new NGramTokenFilter(Constants.VERSION, delegate.getTokenStream(), | |
| + this.min, this.max)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment