From 9ba1122f5545e158a115e264bf1517337feb9695 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Wed, 30 Oct 2013 11:11:17 +0000 Subject: [PATCH] LUCENE-5313: move preservePositionIncrements from setter to ctor git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1537038 13f79535-47bb-0310-9956-ffa450edef68 --- lucene/CHANGES.txt | 3 ++ .../suggest/analyzing/AnalyzingSuggester.java | 32 +++++++-------- .../suggest/analyzing/FuzzySuggester.java | 9 +++-- .../analyzing/AnalyzingSuggesterTest.java | 39 ++++++++++--------- .../suggest/analyzing/FuzzySuggesterTest.java | 22 +++++------ .../suggest/fst/AnalyzingLookupFactory.java | 12 +++++- .../suggest/fst/FuzzyLookupFactory.java | 10 +++-- 7 files changed, 72 insertions(+), 55 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 9576d52df4d..8340360ff22 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -195,6 +195,9 @@ API Changes: * LUCENE-5157: Rename OrdinalMap methods to clarify API and internal structure. (Boaz Leskes via Adrien Grand) +* LUCENE-5313: Move preservePositionIncrements from setter to ctor in + Analyzing/FuzzySuggester. (Areek Zillur via Mike McCandless) + Optimizations * LUCENE-5225: The ToParentBlockJoinQuery only keeps tracks of the the child diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java index ee681c747d7..bd4d783f57a 100644 --- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java +++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java @@ -74,8 +74,9 @@ import org.apache.lucene.util.fst.Util; * then the partial text "ghost chr..." could see the * suggestion "The Ghost of Christmas Past". Note that * position increments MUST NOT be preserved for this example - * to work, so you should call - * {@link #setPreservePositionIncrements(boolean) setPreservePositionIncrements(false)}. + * to work, so you should call the constructor with + * preservePositionIncrements parameter set to + * false * *

* If SynonymFilter is used to map wifi and wireless network to @@ -145,14 +146,14 @@ public class AnalyzingSuggester extends Lookup { private final boolean preserveSep; /** Include this flag in the options parameter to {@link - * #AnalyzingSuggester(Analyzer,Analyzer,int,int,int)} to always + * #AnalyzingSuggester(Analyzer,Analyzer,int,int,int,boolean)} to always * return the exact match first, regardless of score. This * has no performance impact but could result in * low-quality suggestions. */ public static final int EXACT_FIRST = 1; /** Include this flag in the options parameter to {@link - * #AnalyzingSuggester(Analyzer,Analyzer,int,int,int)} to preserve + * #AnalyzingSuggester(Analyzer,Analyzer,int,int,int,boolean)} to preserve * token separators when matching. */ public static final int PRESERVE_SEP = 2; @@ -187,21 +188,21 @@ public class AnalyzingSuggester extends Lookup { private boolean preservePositionIncrements; /** - * Calls {@link #AnalyzingSuggester(Analyzer,Analyzer,int,int,int) + * Calls {@link #AnalyzingSuggester(Analyzer,Analyzer,int,int,int,boolean) * AnalyzingSuggester(analyzer, analyzer, EXACT_FIRST | - * PRESERVE_SEP, 256, -1)} + * PRESERVE_SEP, 256, -1, false)} */ public AnalyzingSuggester(Analyzer analyzer) { - this(analyzer, analyzer, EXACT_FIRST | PRESERVE_SEP, 256, -1); + this(analyzer, analyzer, EXACT_FIRST | PRESERVE_SEP, 256, -1, false); } /** - * Calls {@link #AnalyzingSuggester(Analyzer,Analyzer,int,int,int) + * Calls {@link #AnalyzingSuggester(Analyzer,Analyzer,int,int,int,boolean) * AnalyzingSuggester(indexAnalyzer, queryAnalyzer, EXACT_FIRST | - * PRESERVE_SEP, 256, -1)} + * PRESERVE_SEP, 256, -1, false)} */ public AnalyzingSuggester(Analyzer indexAnalyzer, Analyzer queryAnalyzer) { - this(indexAnalyzer, queryAnalyzer, EXACT_FIRST | PRESERVE_SEP, 256, -1); + this(indexAnalyzer, queryAnalyzer, EXACT_FIRST | PRESERVE_SEP, 256, -1, false); } /** @@ -219,8 +220,11 @@ public class AnalyzingSuggester extends Lookup { * @param maxGraphExpansions Maximum number of graph paths * to expand from the analyzed form. Set this to -1 for * no limit. + * @param preservePositionIncrements Whether position holes + * should appear in the automata */ - public AnalyzingSuggester(Analyzer indexAnalyzer, Analyzer queryAnalyzer, int options, int maxSurfaceFormsPerAnalyzedForm, int maxGraphExpansions) { + public AnalyzingSuggester(Analyzer indexAnalyzer, Analyzer queryAnalyzer, int options, int maxSurfaceFormsPerAnalyzedForm, int maxGraphExpansions, + boolean preservePositionIncrements) { this.indexAnalyzer = indexAnalyzer; this.queryAnalyzer = queryAnalyzer; if ((options & ~(EXACT_FIRST | PRESERVE_SEP)) != 0) { @@ -242,12 +246,6 @@ public class AnalyzingSuggester extends Lookup { throw new IllegalArgumentException("maxGraphExpansions must -1 (no limit) or > 0 (got: " + maxGraphExpansions + ")"); } this.maxGraphExpansions = maxGraphExpansions; - preservePositionIncrements = true; - } - - /** Whether to take position holes (position increment > 1) into account when - * building the automaton, true by default. */ - public void setPreservePositionIncrements(boolean preservePositionIncrements) { this.preservePositionIncrements = preservePositionIncrements; } diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/FuzzySuggester.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/FuzzySuggester.java index 2456a90480e..f319c82c47a 100644 --- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/FuzzySuggester.java +++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/FuzzySuggester.java @@ -124,7 +124,7 @@ public final class FuzzySuggester extends AnalyzingSuggester { * Analyzer that will be used for analyzing query text during lookup */ public FuzzySuggester(Analyzer indexAnalyzer, Analyzer queryAnalyzer) { - this(indexAnalyzer, queryAnalyzer, EXACT_FIRST | PRESERVE_SEP, 256, -1, DEFAULT_MAX_EDITS, DEFAULT_TRANSPOSITIONS, + this(indexAnalyzer, queryAnalyzer, EXACT_FIRST | PRESERVE_SEP, 256, -1, false, DEFAULT_MAX_EDITS, DEFAULT_TRANSPOSITIONS, DEFAULT_NON_FUZZY_PREFIX, DEFAULT_MIN_FUZZY_LENGTH, DEFAULT_UNICODE_AWARE); } @@ -143,6 +143,7 @@ public final class FuzzySuggester extends AnalyzingSuggester { * @param maxGraphExpansions Maximum number of graph paths * to expand from the analyzed form. Set this to -1 for * no limit. + * @param preservePositionIncrements Whether position holes should appear in the automaton * @param maxEdits must be >= 0 and <= {@link LevenshteinAutomata#MAXIMUM_SUPPORTED_DISTANCE} . * @param transpositions true if transpositions should be treated as a primitive * edit operation. If this is false, comparisons will implement the classic @@ -153,9 +154,9 @@ public final class FuzzySuggester extends AnalyzingSuggester { */ public FuzzySuggester(Analyzer indexAnalyzer, Analyzer queryAnalyzer, int options, int maxSurfaceFormsPerAnalyzedForm, int maxGraphExpansions, - int maxEdits, boolean transpositions, int nonFuzzyPrefix, - int minFuzzyLength, boolean unicodeAware) { - super(indexAnalyzer, queryAnalyzer, options, maxSurfaceFormsPerAnalyzedForm, maxGraphExpansions); + boolean preservePositionIncrements, int maxEdits, boolean transpositions, + int nonFuzzyPrefix, int minFuzzyLength, boolean unicodeAware) { + super(indexAnalyzer, queryAnalyzer, options, maxSurfaceFormsPerAnalyzedForm, maxGraphExpansions, preservePositionIncrements); if (maxEdits < 0 || maxEdits > LevenshteinAutomata.MAXIMUM_SUPPORTED_DISTANCE) { throw new IllegalArgumentException("maxEdits must be between 0 and " + LevenshteinAutomata.MAXIMUM_SUPPORTED_DISTANCE); } diff --git a/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggesterTest.java b/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggesterTest.java index eca1d2689a7..21b5162e768 100644 --- a/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggesterTest.java +++ b/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggesterTest.java @@ -175,9 +175,8 @@ public class AnalyzingSuggesterTest extends LuceneTestCase { mapping.put(title, Long.valueOf(randomWeight)); } } - - AnalyzingSuggester analyzingSuggester = new AnalyzingSuggester(new MockAnalyzer(random())); - analyzingSuggester.setPreservePositionIncrements(random().nextBoolean()); + AnalyzingSuggester analyzingSuggester = new AnalyzingSuggester(new MockAnalyzer(random()), new MockAnalyzer(random()), + AnalyzingSuggester.EXACT_FIRST | AnalyzingSuggester.PRESERVE_SEP, 256, -1, random().nextBoolean()); boolean doPayloads = random().nextBoolean(); if (doPayloads) { List keysAndPayloads = new ArrayList<>(); @@ -214,8 +213,9 @@ public class AnalyzingSuggesterTest extends LuceneTestCase { }; Analyzer standard = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, true, MockTokenFilter.ENGLISH_STOPSET); - AnalyzingSuggester suggester = new AnalyzingSuggester(standard); - suggester.setPreservePositionIncrements(false); + AnalyzingSuggester suggester = new AnalyzingSuggester(standard, standard, + AnalyzingSuggester.EXACT_FIRST | AnalyzingSuggester.PRESERVE_SEP, 256, -1, false); + suggester.build(new InputArrayIterator(keys)); List results = suggester.lookup(_TestUtil.stringToCharSequence("the ghost of chris", random()), false, 1); @@ -254,7 +254,7 @@ public class AnalyzingSuggesterTest extends LuceneTestCase { int options = 0; Analyzer a = new MockAnalyzer(random()); - AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, options, 256, -1); + AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, options, 256, -1, false); suggester.build(new InputArrayIterator(keys)); // TODO: would be nice if "ab " would allow the test to // pass, and more generally if the analyzer can know @@ -459,7 +459,8 @@ public class AnalyzingSuggesterTest extends LuceneTestCase { public void testExactFirst() throws Exception { Analyzer a = getUnusualAnalyzer(); - AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, AnalyzingSuggester.EXACT_FIRST | AnalyzingSuggester.PRESERVE_SEP, 256, -1); + int options = AnalyzingSuggester.EXACT_FIRST | AnalyzingSuggester.PRESERVE_SEP; + AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, options, 256, -1, false); suggester.build(new InputArrayIterator(new Input[] { new Input("x y", 1), new Input("x y z", 3), @@ -498,7 +499,7 @@ public class AnalyzingSuggesterTest extends LuceneTestCase { public void testNonExactFirst() throws Exception { Analyzer a = getUnusualAnalyzer(); - AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, AnalyzingSuggester.PRESERVE_SEP, 256, -1); + AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, AnalyzingSuggester.PRESERVE_SEP, 256, -1, false); suggester.build(new InputArrayIterator(new Input[] { new Input("x y", 1), @@ -752,7 +753,7 @@ public class AnalyzingSuggesterTest extends LuceneTestCase { Analyzer a = new MockTokenEatingAnalyzer(numStopChars, preserveHoles); AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, - preserveSep ? AnalyzingSuggester.PRESERVE_SEP : 0, 256, -1); + preserveSep ? AnalyzingSuggester.PRESERVE_SEP : 0, 256, -1, false); if (doPayloads) { suggester.build(new InputArrayIterator(shuffle(payloadKeys))); } else { @@ -873,7 +874,7 @@ public class AnalyzingSuggesterTest extends LuceneTestCase { public void testMaxSurfaceFormsPerAnalyzedForm() throws Exception { Analyzer a = new MockAnalyzer(random()); - AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, 0, 2, -1); + AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, 0, 2, -1, false); suggester.build(new InputArrayIterator(shuffle(new Input("a", 40), new Input("a ", 50), new Input(" a", 60)))); @@ -887,7 +888,7 @@ public class AnalyzingSuggesterTest extends LuceneTestCase { public void testQueueExhaustion() throws Exception { Analyzer a = new MockAnalyzer(random()); - AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, AnalyzingSuggester.EXACT_FIRST, 256, -1); + AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, AnalyzingSuggester.EXACT_FIRST, 256, -1, false); suggester.build(new InputArrayIterator(new Input[] { new Input("a", 2), @@ -903,7 +904,7 @@ public class AnalyzingSuggesterTest extends LuceneTestCase { Analyzer a = new MockAnalyzer(random()); - AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, AnalyzingSuggester.EXACT_FIRST, 256, -1); + AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, AnalyzingSuggester.EXACT_FIRST, 256, -1, false); suggester.build(new InputArrayIterator(new Input[] { new Input("a", 5), @@ -968,7 +969,7 @@ public class AnalyzingSuggesterTest extends LuceneTestCase { } }; - AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, 0, 256, -1); + AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, 0, 256, -1, false); suggester.build(new InputArrayIterator(shuffle( new Input("hambone", 6), @@ -1037,7 +1038,7 @@ public class AnalyzingSuggesterTest extends LuceneTestCase { } }; - AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, 0, 256, -1); + AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, 0, 256, -1, false); suggester.build(new InputArrayIterator(new Input[] { new Input("a", 6), @@ -1110,7 +1111,7 @@ public class AnalyzingSuggesterTest extends LuceneTestCase { } }; - AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, 0, 256, -1); + AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, 0, 256, -1, false); suggester.build(new InputArrayIterator(new Input[] { new Input("a a", 50), @@ -1120,7 +1121,7 @@ public class AnalyzingSuggesterTest extends LuceneTestCase { public void testDupSurfaceFormsMissingResults3() throws Exception { Analyzer a = new MockAnalyzer(random()); - AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, AnalyzingSuggester.PRESERVE_SEP, 256, -1); + AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, AnalyzingSuggester.PRESERVE_SEP, 256, -1, false); suggester.build(new InputArrayIterator(new Input[] { new Input("a a", 7), new Input("a a", 7), @@ -1133,7 +1134,7 @@ public class AnalyzingSuggesterTest extends LuceneTestCase { public void testEndingSpace() throws Exception { Analyzer a = new MockAnalyzer(random()); - AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, AnalyzingSuggester.PRESERVE_SEP, 256, -1); + AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, AnalyzingSuggester.PRESERVE_SEP, 256, -1, false); suggester.build(new InputArrayIterator(new Input[] { new Input("i love lucy", 7), new Input("isla de muerta", 8), @@ -1166,14 +1167,14 @@ public class AnalyzingSuggesterTest extends LuceneTestCase { } }; - AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, 0, 256, 1); + AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, 0, 256, 1, false); suggester.build(new InputArrayIterator(new Input[] {new Input("a", 1)})); assertEquals("[a/1]", suggester.lookup("a", false, 1).toString()); } public void testIllegalLookupArgument() throws Exception { Analyzer a = new MockAnalyzer(random()); - AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, 0, 256, -1); + AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, 0, 256, -1, false); suggester.build(new InputArrayIterator(new Input[] { new Input("а где Люси?", 7), })); diff --git a/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/FuzzySuggesterTest.java b/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/FuzzySuggesterTest.java index 3d24856b0c3..f2239e29122 100644 --- a/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/FuzzySuggesterTest.java +++ b/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/FuzzySuggesterTest.java @@ -61,7 +61,7 @@ public class FuzzySuggesterTest extends LuceneTestCase { } keys.add(new Input("foo bar boo far", 12)); MockAnalyzer analyzer = new MockAnalyzer(random(), MockTokenizer.KEYWORD, false); - FuzzySuggester suggester = new FuzzySuggester(analyzer, analyzer, FuzzySuggester.EXACT_FIRST | FuzzySuggester.PRESERVE_SEP, 256, -1, FuzzySuggester.DEFAULT_MAX_EDITS, FuzzySuggester.DEFAULT_TRANSPOSITIONS, + FuzzySuggester suggester = new FuzzySuggester(analyzer, analyzer, FuzzySuggester.EXACT_FIRST | FuzzySuggester.PRESERVE_SEP, 256, -1, false, FuzzySuggester.DEFAULT_MAX_EDITS, FuzzySuggester.DEFAULT_TRANSPOSITIONS, 0, FuzzySuggester.DEFAULT_MIN_FUZZY_LENGTH, FuzzySuggester.DEFAULT_UNICODE_AWARE); suggester.build(new InputArrayIterator(keys)); int numIters = atLeast(10); @@ -82,7 +82,7 @@ public class FuzzySuggesterTest extends LuceneTestCase { } keys.add(new Input("фуу бар буу фар", 12)); MockAnalyzer analyzer = new MockAnalyzer(random(), MockTokenizer.KEYWORD, false); - FuzzySuggester suggester = new FuzzySuggester(analyzer, analyzer, FuzzySuggester.EXACT_FIRST | FuzzySuggester.PRESERVE_SEP, 256, -1, FuzzySuggester.DEFAULT_MAX_EDITS, FuzzySuggester.DEFAULT_TRANSPOSITIONS, + FuzzySuggester suggester = new FuzzySuggester(analyzer, analyzer, FuzzySuggester.EXACT_FIRST | FuzzySuggester.PRESERVE_SEP, 256, -1, false, FuzzySuggester.DEFAULT_MAX_EDITS, FuzzySuggester.DEFAULT_TRANSPOSITIONS, 0, FuzzySuggester.DEFAULT_MIN_FUZZY_LENGTH, true); suggester.build(new InputArrayIterator(keys)); int numIters = atLeast(10); @@ -177,8 +177,8 @@ public class FuzzySuggesterTest extends LuceneTestCase { }; Analyzer standard = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, true, MockTokenFilter.ENGLISH_STOPSET); - FuzzySuggester suggester = new FuzzySuggester(standard); - suggester.setPreservePositionIncrements(false); + FuzzySuggester suggester = new FuzzySuggester(standard, standard, AnalyzingSuggester.EXACT_FIRST | AnalyzingSuggester.PRESERVE_SEP, 256, -1, false, FuzzySuggester.DEFAULT_MAX_EDITS, FuzzySuggester.DEFAULT_TRANSPOSITIONS, + FuzzySuggester.DEFAULT_NON_FUZZY_PREFIX, FuzzySuggester.DEFAULT_MIN_FUZZY_LENGTH, FuzzySuggester.DEFAULT_UNICODE_AWARE); suggester.build(new InputArrayIterator(keys)); List results = suggester.lookup(_TestUtil.stringToCharSequence("the ghost of chris", random()), false, 1); @@ -208,7 +208,7 @@ public class FuzzySuggesterTest extends LuceneTestCase { int options = 0; Analyzer a = new MockAnalyzer(random()); - FuzzySuggester suggester = new FuzzySuggester(a, a, options, 256, -1, 1, true, 1, 3, false); + FuzzySuggester suggester = new FuzzySuggester(a, a, options, 256, -1, false, 1, true, 1, 3, false); suggester.build(new InputArrayIterator(keys)); // TODO: would be nice if "ab " would allow the test to // pass, and more generally if the analyzer can know @@ -417,7 +417,7 @@ public class FuzzySuggesterTest extends LuceneTestCase { public void testExactFirst() throws Exception { Analyzer a = getUnusualAnalyzer(); - FuzzySuggester suggester = new FuzzySuggester(a, a, AnalyzingSuggester.EXACT_FIRST | AnalyzingSuggester.PRESERVE_SEP, 256, -1, 1, true, 1, 3, false); + FuzzySuggester suggester = new FuzzySuggester(a, a, AnalyzingSuggester.EXACT_FIRST | AnalyzingSuggester.PRESERVE_SEP, 256, -1, false, 1, true, 1, 3, false); suggester.build(new InputArrayIterator(new Input[] { new Input("x y", 1), new Input("x y z", 3), @@ -456,7 +456,7 @@ public class FuzzySuggesterTest extends LuceneTestCase { public void testNonExactFirst() throws Exception { Analyzer a = getUnusualAnalyzer(); - FuzzySuggester suggester = new FuzzySuggester(a, a, AnalyzingSuggester.PRESERVE_SEP, 256, -1, 1, true, 1, 3, false); + FuzzySuggester suggester = new FuzzySuggester(a, a, AnalyzingSuggester.PRESERVE_SEP, 256, -1, false, 1, true, 1, 3, false); suggester.build(new InputArrayIterator(new Input[] { new Input("x y", 1), @@ -683,7 +683,7 @@ public class FuzzySuggesterTest extends LuceneTestCase { Analyzer a = new MockTokenEatingAnalyzer(numStopChars, preserveHoles); FuzzySuggester suggester = new FuzzySuggester(a, a, - preserveSep ? AnalyzingSuggester.PRESERVE_SEP : 0, 256, -1, 1, false, 1, 3, unicodeAware); + preserveSep ? AnalyzingSuggester.PRESERVE_SEP : 0, 256, -1, false, 1, false, 1, 3, unicodeAware); suggester.build(new InputArrayIterator(keys)); for (String prefix : allPrefixes) { @@ -823,7 +823,7 @@ public class FuzzySuggesterTest extends LuceneTestCase { public void testMaxSurfaceFormsPerAnalyzedForm() throws Exception { Analyzer a = new MockAnalyzer(random()); - FuzzySuggester suggester = new FuzzySuggester(a, a, 0, 2, -1, 1, true, 1, 3, false); + FuzzySuggester suggester = new FuzzySuggester(a, a, 0, 2, -1, false, 1, true, 1, 3, false); List keys = Arrays.asList(new Input[] { new Input("a", 40), @@ -844,7 +844,7 @@ public class FuzzySuggesterTest extends LuceneTestCase { public void testEditSeps() throws Exception { Analyzer a = new MockAnalyzer(random()); - FuzzySuggester suggester = new FuzzySuggester(a, a, FuzzySuggester.PRESERVE_SEP, 2, -1, 2, true, 1, 3, false); + FuzzySuggester suggester = new FuzzySuggester(a, a, FuzzySuggester.PRESERVE_SEP, 2, -1, false, 2, true, 1, 3, false); List keys = Arrays.asList(new Input[] { new Input("foo bar", 40), @@ -958,7 +958,7 @@ public class FuzzySuggesterTest extends LuceneTestCase { boolean transpositions = random().nextBoolean(); // TODO: test graph analyzers // TODO: test exactFirst / preserveSep permutations - FuzzySuggester suggest = new FuzzySuggester(a, a, 0, 256, -1, maxEdits, transpositions, prefixLen, prefixLen, false); + FuzzySuggester suggest = new FuzzySuggester(a, a, 0, 256, -1, false, maxEdits, transpositions, prefixLen, prefixLen, false); if (VERBOSE) { System.out.println("TEST: maxEdits=" + maxEdits + " prefixLen=" + prefixLen + " transpositions=" + transpositions + " num=" + NUM); diff --git a/solr/core/src/java/org/apache/solr/spelling/suggest/fst/AnalyzingLookupFactory.java b/solr/core/src/java/org/apache/solr/spelling/suggest/fst/AnalyzingLookupFactory.java index d4bcb51b4ed..4dd4a186d7d 100644 --- a/solr/core/src/java/org/apache/solr/spelling/suggest/fst/AnalyzingLookupFactory.java +++ b/solr/core/src/java/org/apache/solr/spelling/suggest/fst/AnalyzingLookupFactory.java @@ -64,6 +64,11 @@ public class AnalyzingLookupFactory extends LookupFactory { */ public static final String QUERY_ANALYZER = "suggestAnalyzerFieldType"; + /** + * Whether position holes should appear in the automaton. + */ + public static final String PRESERVE_POSITION_INCREMENTS = "preservePositionIncrements"; + /** * File name for the automaton. * @@ -106,9 +111,14 @@ public class AnalyzingLookupFactory extends LookupFactory { int maxGraphExpansions = params.get(MAX_EXPANSIONS) != null ? Integer.parseInt(params.get(MAX_EXPANSIONS).toString()) : -1; + + boolean preservePositionIncrements = params.get(PRESERVE_POSITION_INCREMENTS) != null + ? Boolean.valueOf(params.get(PRESERVE_POSITION_INCREMENTS).toString()) + : false; - return new AnalyzingSuggester(indexAnalyzer, queryAnalyzer, flags, maxSurfaceFormsPerAnalyzedForm, maxGraphExpansions); + return new AnalyzingSuggester(indexAnalyzer, queryAnalyzer, flags, maxSurfaceFormsPerAnalyzedForm, + maxGraphExpansions, preservePositionIncrements); } @Override diff --git a/solr/core/src/java/org/apache/solr/spelling/suggest/fst/FuzzyLookupFactory.java b/solr/core/src/java/org/apache/solr/spelling/suggest/fst/FuzzyLookupFactory.java index 667097f391d..4eec5939c93 100644 --- a/solr/core/src/java/org/apache/solr/spelling/suggest/fst/FuzzyLookupFactory.java +++ b/solr/core/src/java/org/apache/solr/spelling/suggest/fst/FuzzyLookupFactory.java @@ -106,6 +106,10 @@ public class FuzzyLookupFactory extends LookupFactory { ? Integer.parseInt(params.get(AnalyzingLookupFactory.MAX_EXPANSIONS).toString()) : -1; + boolean preservePositionIncrements = params.get(AnalyzingLookupFactory.PRESERVE_POSITION_INCREMENTS) != null + ? Boolean.valueOf(params.get(AnalyzingLookupFactory.PRESERVE_POSITION_INCREMENTS).toString()) + : false; + int maxEdits = (params.get(MAX_EDITS) != null) ? Integer.parseInt(params.get(MAX_EDITS).toString()) : FuzzySuggester.DEFAULT_MAX_EDITS; @@ -127,9 +131,9 @@ public class FuzzyLookupFactory extends LookupFactory { ? Boolean.valueOf(params.get(UNICODE_AWARE).toString()) : FuzzySuggester.DEFAULT_UNICODE_AWARE; - return new FuzzySuggester(indexAnalyzer, queryAnalyzer, options, - maxSurfaceFormsPerAnalyzedForm, maxGraphExpansions, maxEdits, - transpositions, nonFuzzyPrefix, minFuzzyLength, unicodeAware); + return new FuzzySuggester(indexAnalyzer, queryAnalyzer, options, maxSurfaceFormsPerAnalyzedForm, + maxGraphExpansions, preservePositionIncrements, maxEdits, transpositions, nonFuzzyPrefix, + minFuzzyLength, unicodeAware); } @Override