mirror of https://github.com/apache/lucene.git
LUCENE-6515: Cleanup ContextSuggestField API and remove unused code
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1683131 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8f9240abfe
commit
cecebbc750
|
@ -20,7 +20,6 @@ package org.apache.lucene.search.suggest.document;
|
|||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.LeafReader;
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
import org.apache.lucene.index.Term;
|
||||
|
@ -49,20 +48,15 @@ import org.apache.lucene.util.automaton.Automaton;
|
|||
public class CompletionWeight extends Weight {
|
||||
private final CompletionQuery completionQuery;
|
||||
private final Automaton automaton;
|
||||
private final long maxWeight;
|
||||
private final long minWeight;
|
||||
|
||||
/**
|
||||
* Creates a weight for <code>query</code> with an <code>automaton</code>,
|
||||
* using the <code>reader</code> for index stats
|
||||
*/
|
||||
public CompletionWeight(final IndexReader reader, final CompletionQuery query,
|
||||
final Automaton automaton) throws IOException {
|
||||
public CompletionWeight(final CompletionQuery query, final Automaton automaton) throws IOException {
|
||||
super(query);
|
||||
this.completionQuery = query;
|
||||
this.automaton = automaton;
|
||||
this.minWeight = minWeight(query.getField(), reader);
|
||||
this.maxWeight = maxWeight(query.getField(), reader);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -139,49 +133,6 @@ public class CompletionWeight extends Weight {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static long minWeight(String field, IndexReader reader) {
|
||||
long minWeight = Long.MAX_VALUE;
|
||||
Terms terms;
|
||||
for (LeafReaderContext context : reader.leaves()) {
|
||||
LeafReader leafReader = context.reader();
|
||||
try {
|
||||
if ((terms = leafReader.terms(field)) == null) {
|
||||
continue;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
continue;
|
||||
}
|
||||
if (terms instanceof CompletionTerms) {
|
||||
CompletionTerms completionTerms = (CompletionTerms) terms;
|
||||
minWeight = Math.min(completionTerms.getMinWeight(), minWeight);
|
||||
}
|
||||
}
|
||||
if (minWeight == Long.MAX_VALUE) {
|
||||
minWeight = 0;
|
||||
}
|
||||
return minWeight;
|
||||
}
|
||||
|
||||
private static long maxWeight(String field, IndexReader reader) {
|
||||
long maxWeight = 0;
|
||||
Terms terms;
|
||||
for (LeafReaderContext context : reader.leaves()) {
|
||||
LeafReader leafReader = context.reader();
|
||||
try {
|
||||
if ((terms = leafReader.terms(field)) == null) {
|
||||
continue;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
continue;
|
||||
}
|
||||
if (terms instanceof CompletionTerms) {
|
||||
CompletionTerms completionTerms = (CompletionTerms) terms;
|
||||
maxWeight = Math.max(completionTerms.getMaxWeight(), maxWeight);
|
||||
}
|
||||
}
|
||||
return maxWeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
|
|
|
@ -24,7 +24,6 @@ import java.util.Iterator;
|
|||
import java.util.Map;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.Weight;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
|
@ -205,8 +204,7 @@ public class ContextQuery extends CompletionQuery {
|
|||
for (int i = 0; iterator.hasNext(); i++) {
|
||||
contextLengthArray[i] = iterator.next();
|
||||
}
|
||||
return new ContextCompletionWeight(searcher.getIndexReader(), this, contextsAutomaton,
|
||||
innerWeight, contextMap, contextLengthArray);
|
||||
return new ContextCompletionWeight(this, contextsAutomaton, innerWeight, contextMap, contextLengthArray);
|
||||
}
|
||||
|
||||
private static class ContextMetaData {
|
||||
|
@ -229,11 +227,10 @@ public class ContextQuery extends CompletionQuery {
|
|||
private float currentBoost;
|
||||
private CharSequence currentContext;
|
||||
|
||||
public ContextCompletionWeight(IndexReader reader, CompletionQuery query,
|
||||
Automaton automaton, CompletionWeight innerWeight,
|
||||
public ContextCompletionWeight(CompletionQuery query, Automaton automaton, CompletionWeight innerWeight,
|
||||
Map<IntsRef, Float> contextMap,
|
||||
int[] contextLengths) throws IOException {
|
||||
super(reader, query, automaton);
|
||||
super(query, automaton);
|
||||
this.contextMap = contextMap;
|
||||
this.contextLengths = contextLengths;
|
||||
this.innerWeight = innerWeight;
|
||||
|
@ -258,7 +255,8 @@ public class ContextQuery extends CompletionQuery {
|
|||
ref.offset++;
|
||||
assert ref.offset < ref.length;
|
||||
}
|
||||
assert ref.ints[ref.offset] == ContextSuggestField.CONTEXT_SEPARATOR : "expected CONTEXT_SEPARATOR at offset=" + ref.offset;
|
||||
assert ref.ints[ref.offset] == ContextSuggestField.CONTEXT_SEPARATOR :
|
||||
"expected CONTEXT_SEPARATOR at offset=" + ref.offset;
|
||||
if (ref.offset > pathPrefix.offset) {
|
||||
currentContext = Util.toBytesRef(new IntsRef(pathPrefix.ints, pathPrefix.offset, ref.offset), scratch).utf8ToString();
|
||||
} else {
|
||||
|
|
|
@ -18,7 +18,6 @@ package org.apache.lucene.search.suggest.document;
|
|||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
@ -58,24 +57,23 @@ public class ContextSuggestField extends SuggestField {
|
|||
* Creates a context-enabled suggest field
|
||||
*
|
||||
* @param name field name
|
||||
* @param contexts associated contexts
|
||||
* @param value field value to get suggestion on
|
||||
* @param weight field weight
|
||||
* @param contexts associated contexts
|
||||
*
|
||||
* @throws IllegalArgumentException if either the name or value is null,
|
||||
* if value is an empty string, if the weight is negative, if value or
|
||||
* contexts contains any reserved characters
|
||||
*/
|
||||
public ContextSuggestField(String name, Collection<CharSequence> contexts, String value, int weight) {
|
||||
public ContextSuggestField(String name, String value, int weight, CharSequence... contexts) {
|
||||
super(name, value, weight);
|
||||
validate(value);
|
||||
this.contexts = new HashSet<>((contexts != null) ? contexts.length : 0);
|
||||
if (contexts != null) {
|
||||
for (CharSequence context : contexts) {
|
||||
validate(context);
|
||||
this.contexts.add(context);
|
||||
}
|
||||
this.contexts = new HashSet<>(contexts);
|
||||
} else {
|
||||
this.contexts = new HashSet<>();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ import java.util.Arrays;
|
|||
import java.util.Set;
|
||||
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.Filter;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
|
@ -152,7 +151,7 @@ public class FuzzyCompletionQuery extends PrefixCompletionQuery {
|
|||
utf8automaton = Operations.determinize(utf8automaton, maxDeterminizedStates);
|
||||
automaton = utf8automaton;
|
||||
}
|
||||
return new FuzzyCompletionWeight(searcher.getIndexReader(), this, automaton, refs);
|
||||
return new FuzzyCompletionWeight(this, automaton, refs);
|
||||
}
|
||||
|
||||
private Automaton toLevenshteinAutomata(Set<IntsRef> ref) {
|
||||
|
@ -218,9 +217,8 @@ public class FuzzyCompletionQuery extends PrefixCompletionQuery {
|
|||
private final Set<IntsRef> refs;
|
||||
int currentBoost = 0;
|
||||
|
||||
public FuzzyCompletionWeight(IndexReader reader, CompletionQuery query,
|
||||
Automaton automaton, Set<IntsRef> refs) throws IOException {
|
||||
super(reader, query, automaton);
|
||||
public FuzzyCompletionWeight(CompletionQuery query, Automaton automaton, Set<IntsRef> refs) throws IOException {
|
||||
super(query, automaton);
|
||||
this.refs = refs;
|
||||
}
|
||||
|
||||
|
|
|
@ -90,12 +90,6 @@ public final class NRTSuggester implements Accountable {
|
|||
*/
|
||||
private final int payloadSep;
|
||||
|
||||
/**
|
||||
* Label used to denote the end of an input in the FST and
|
||||
* the beginning of dedup bytes
|
||||
*/
|
||||
private final int endByte;
|
||||
|
||||
/**
|
||||
* Maximum queue depth for TopNSearcher
|
||||
*
|
||||
|
@ -103,11 +97,10 @@ public final class NRTSuggester implements Accountable {
|
|||
*/
|
||||
private static final long MAX_TOP_N_QUEUE_SIZE = 5000;
|
||||
|
||||
private NRTSuggester(FST<Pair<Long, BytesRef>> fst, int maxAnalyzedPathsPerOutput, int payloadSep, int endByte) {
|
||||
private NRTSuggester(FST<Pair<Long, BytesRef>> fst, int maxAnalyzedPathsPerOutput, int payloadSep) {
|
||||
this.fst = fst;
|
||||
this.maxAnalyzedPathsPerOutput = maxAnalyzedPathsPerOutput;
|
||||
this.payloadSep = payloadSep;
|
||||
this.endByte = endByte;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -170,7 +163,7 @@ public final class NRTSuggester implements Accountable {
|
|||
}
|
||||
// hits are also returned by search()
|
||||
// we do not use it, instead collect at acceptResult
|
||||
Util.TopResults<Pair<Long, BytesRef>> search = searcher.search();
|
||||
searcher.search();
|
||||
// search admissibility is not guaranteed
|
||||
// see comment on getMaxTopNSearcherQueueSize
|
||||
// assert search.isComplete;
|
||||
|
@ -241,10 +234,14 @@ public final class NRTSuggester implements Accountable {
|
|||
|
||||
/* read some meta info */
|
||||
int maxAnalyzedPathsPerOutput = input.readVInt();
|
||||
/*
|
||||
* Label used to denote the end of an input in the FST and
|
||||
* the beginning of dedup bytes
|
||||
*/
|
||||
int endByte = input.readVInt();
|
||||
int payloadSep = input.readVInt();
|
||||
|
||||
return new NRTSuggester(fst, maxAnalyzedPathsPerOutput, payloadSep, endByte);
|
||||
return new NRTSuggester(fst, maxAnalyzedPathsPerOutput, payloadSep);
|
||||
}
|
||||
|
||||
static long encode(long input) {
|
||||
|
|
|
@ -69,6 +69,6 @@ public class PrefixCompletionQuery extends CompletionQuery {
|
|||
@Override
|
||||
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
|
||||
CompletionTokenStream stream = (CompletionTokenStream) analyzer.tokenStream(getField(), getTerm().text());
|
||||
return new CompletionWeight(searcher.getIndexReader(), this, stream.toAutomaton());
|
||||
return new CompletionWeight(this, stream.toAutomaton());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,7 +90,6 @@ public class RegexCompletionQuery extends CompletionQuery {
|
|||
|
||||
@Override
|
||||
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
|
||||
return new CompletionWeight(searcher.getIndexReader(), this,
|
||||
new RegExp(getTerm().text(), flags).toAutomaton(maxDeterminizedStates));
|
||||
return new CompletionWeight(this, new RegExp(getTerm().text(), flags).toAutomaton(maxDeterminizedStates));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ package org.apache.lucene.search.suggest.document;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -73,13 +72,13 @@ public class TestContextQuery extends LuceneTestCase {
|
|||
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwcWithSuggestField(analyzer, "suggest_field"));
|
||||
Document document = new Document();
|
||||
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type1"), "suggestion1", 8));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type2"), "suggestion2", 7));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type3"), "suggestion3", 6));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion1", 8, "type1"));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion2", 7, "type2"));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion3", 6, "type3"));
|
||||
iw.addDocument(document);
|
||||
|
||||
document = new Document();
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type4"), "suggestion4", 5));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion4", 5, "type4"));
|
||||
iw.addDocument(document);
|
||||
|
||||
if (rarely()) {
|
||||
|
@ -142,13 +141,13 @@ public class TestContextQuery extends LuceneTestCase {
|
|||
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwcWithSuggestField(analyzer, "suggest_field"));
|
||||
Document document = new Document();
|
||||
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type1"), "suggestion1", 4));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type2"), "suggestion2", 3));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type3"), "suggestion3", 2));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion1", 4, "type1"));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion2", 3, "type2"));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion3", 2, "type3"));
|
||||
iw.addDocument(document);
|
||||
|
||||
document = new Document();
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type4"), "suggestion4", 1));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion4", 1, "type4"));
|
||||
iw.addDocument(document);
|
||||
|
||||
if (rarely()) {
|
||||
|
@ -176,8 +175,8 @@ public class TestContextQuery extends LuceneTestCase {
|
|||
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwcWithSuggestField(analyzer, "suggest_field"));
|
||||
Document document = new Document();
|
||||
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("typetype"), "suggestion1", 4));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type"), "suggestion2", 3));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion1", 4, "typetype"));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion2", 3, "type"));
|
||||
iw.addDocument(document);
|
||||
|
||||
if (rarely()) {
|
||||
|
@ -205,11 +204,11 @@ public class TestContextQuery extends LuceneTestCase {
|
|||
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwcWithSuggestField(analyzer, "suggest_field"));
|
||||
Document document = new Document();
|
||||
|
||||
document.add(new ContextSuggestField("suggest_field", null, "suggestion_no_ctx", 4));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion_no_ctx", 4));
|
||||
iw.addDocument(document);
|
||||
|
||||
document = new Document();
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type4"), "suggestion", 1));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion", 1, "type4"));
|
||||
iw.addDocument(document);
|
||||
|
||||
if (rarely()) {
|
||||
|
@ -234,13 +233,13 @@ public class TestContextQuery extends LuceneTestCase {
|
|||
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwcWithSuggestField(analyzer, "suggest_field"));
|
||||
Document document = new Document();
|
||||
|
||||
document.add(new ContextSuggestField("suggest_field", null, "suggestion1", 4));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.emptyList(), "suggestion2", 3));
|
||||
document.add(new ContextSuggestField("suggest_field", null, "suggestion3", 2));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion1", 4));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion2", 3));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion3", 2));
|
||||
iw.addDocument(document);
|
||||
|
||||
document = new Document();
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type4"), "suggestion4", 1));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion4", 1, "type4"));
|
||||
iw.addDocument(document);
|
||||
|
||||
if (rarely()) {
|
||||
|
@ -270,11 +269,11 @@ public class TestContextQuery extends LuceneTestCase {
|
|||
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwcWithSuggestField(analyzer, "suggest_field"));
|
||||
Document document = new Document();
|
||||
|
||||
document.add(new ContextSuggestField("suggest_field", Arrays.asList("type1", "type2", "type3"), "suggestion", 4));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion", 4, "type1", "type2", "type3"));
|
||||
iw.addDocument(document);
|
||||
|
||||
document = new Document();
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type4"), "suggestion", 1));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion", 1, "type4"));
|
||||
iw.addDocument(document);
|
||||
|
||||
if (rarely()) {
|
||||
|
@ -306,13 +305,13 @@ public class TestContextQuery extends LuceneTestCase {
|
|||
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwcWithSuggestField(analyzer, "suggest_field"));
|
||||
Document document = new Document();
|
||||
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type1"), "suggestion1", 4));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type2"), "suggestion2", 3));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type3"), "suggestion3", 2));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion1", 4, "type1"));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion2", 3, "type2"));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion3", 2, "type3"));
|
||||
iw.addDocument(document);
|
||||
|
||||
document = new Document();
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type4"), "suggestion4", 1));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion4", 1, "type4"));
|
||||
iw.addDocument(document);
|
||||
|
||||
if (rarely()) {
|
||||
|
@ -343,13 +342,13 @@ public class TestContextQuery extends LuceneTestCase {
|
|||
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwcWithSuggestField(analyzer, "suggest_field"));
|
||||
Document document = new Document();
|
||||
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type1"), "suggestion1", 4));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type2"), "suggestion2", 3));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type3"), "suggestion3", 2));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion1", 4, "type1"));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion2", 3, "type2"));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion3", 2, "type3"));
|
||||
iw.addDocument(document);
|
||||
|
||||
document = new Document();
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type4"), "suggestion4", 1));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion4", 1, "type4"));
|
||||
iw.addDocument(document);
|
||||
|
||||
if (rarely()) {
|
||||
|
@ -377,13 +376,13 @@ public class TestContextQuery extends LuceneTestCase {
|
|||
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwcWithSuggestField(analyzer, "suggest_field"));
|
||||
Document document = new Document();
|
||||
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type1"), "suggestion1", 4));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type2"), "suggestion2", 3));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type3"), "suggestion3", 2));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion1", 4, "type1"));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion2", 3, "type2"));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion3", 2, "type3"));
|
||||
iw.addDocument(document);
|
||||
|
||||
document = new Document();
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type4"), "suggestion4", 1));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion4", 1, "type4"));
|
||||
iw.addDocument(document);
|
||||
|
||||
if (rarely()) {
|
||||
|
@ -410,13 +409,13 @@ public class TestContextQuery extends LuceneTestCase {
|
|||
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwcWithSuggestField(analyzer, "suggest_field"));
|
||||
Document document = new Document();
|
||||
|
||||
document.add(new ContextSuggestField("suggest_field", Arrays.asList("type1", "type3"), "suggestion1", 8));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type2"), "suggestion2", 7));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type3"), "suggestion3", 6));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion1", 8, "type1", "type3"));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion2", 7, "type2"));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion3", 6, "type3"));
|
||||
iw.addDocument(document);
|
||||
|
||||
document = new Document();
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type4"), "suggestion4", 5));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion4", 5, "type4"));
|
||||
iw.addDocument(document);
|
||||
|
||||
if (rarely()) {
|
||||
|
@ -448,13 +447,13 @@ public class TestContextQuery extends LuceneTestCase {
|
|||
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwcWithSuggestField(analyzer, "suggest_field"));
|
||||
Document document = new Document();
|
||||
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type1"), "suggestion1", 4));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type2"), "suggestion2", 3));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type3"), "suggestion3", 2));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion1", 4, "type1"));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion2", 3, "type2"));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion3", 2, "type3"));
|
||||
iw.addDocument(document);
|
||||
|
||||
document = new Document();
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type4"), "suggestion4", 1));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion4", 1, "type4"));
|
||||
iw.addDocument(document);
|
||||
|
||||
if (rarely()) {
|
||||
|
@ -496,7 +495,7 @@ public class TestContextQuery extends LuceneTestCase {
|
|||
}
|
||||
seenWeights.add(weight);
|
||||
Document document = new Document();
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList(context), suggestion, weight));
|
||||
document.add(new ContextSuggestField("suggest_field", suggestion, weight, context));
|
||||
iw.addDocument(document);
|
||||
expectedEntries.add(new Entry(suggestion, context.toString(), i * weight));
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@ package org.apache.lucene.search.suggest.document;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.analysis.MockAnalyzer;
|
||||
import org.apache.lucene.document.Document;
|
||||
|
@ -53,7 +51,7 @@ public class TestContextSuggestField extends LuceneTestCase {
|
|||
@Test
|
||||
public void testEmptySuggestion() throws Exception {
|
||||
try {
|
||||
new ContextSuggestField("suggest_field", Collections.singletonList("type1"), "", 1);
|
||||
new ContextSuggestField("suggest_field", "", 1, "type1");
|
||||
fail("no exception thrown when indexing zero length suggestion");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertTrue(expected.getMessage().contains("value"));
|
||||
|
@ -66,14 +64,14 @@ public class TestContextSuggestField extends LuceneTestCase {
|
|||
charsRefBuilder.append("sugg");
|
||||
charsRefBuilder.setCharAt(2, (char) ContextSuggestField.CONTEXT_SEPARATOR);
|
||||
try {
|
||||
new ContextSuggestField("name", Collections.singletonList(charsRefBuilder.toString()), "sugg", 1);
|
||||
new ContextSuggestField("name", "sugg", 1, charsRefBuilder.toString());
|
||||
fail("no exception thrown for context value containing CONTEXT_SEPARATOR:" + ContextSuggestField.CONTEXT_SEPARATOR);
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertTrue(e.getMessage().contains("[0x1d]"));
|
||||
}
|
||||
|
||||
try {
|
||||
new ContextSuggestField("name", Collections.singletonList("sugg"), charsRefBuilder.toString(), 1);
|
||||
new ContextSuggestField("name", charsRefBuilder.toString(), 1, "sugg");
|
||||
fail("no exception thrown for value containing CONTEXT_SEPARATOR:" + ContextSuggestField.CONTEXT_SEPARATOR);
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertTrue(e.getMessage().contains("[0x1d]"));
|
||||
|
@ -85,7 +83,7 @@ public class TestContextSuggestField extends LuceneTestCase {
|
|||
Analyzer analyzer = new MockAnalyzer(random());
|
||||
Document document = new Document();
|
||||
document.add(new SuggestField("suggest_field", "suggestion1", 4));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.emptyList(), "suggestion2", 3));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion2", 3));
|
||||
|
||||
try (RandomIndexWriter iw = new RandomIndexWriter(random(), dir,
|
||||
iwcWithSuggestField(analyzer, "suggest_field"))) {
|
||||
|
@ -107,14 +105,14 @@ public class TestContextSuggestField extends LuceneTestCase {
|
|||
document.add(new SuggestField("suggest_field", "suggestion1", 4));
|
||||
document.add(new SuggestField("suggest_field", "suggestion2", 3));
|
||||
document.add(new SuggestField("suggest_field", "suggestion3", 2));
|
||||
document.add(new ContextSuggestField("context_suggest_field", Collections.singletonList("type1"), "suggestion1", 4));
|
||||
document.add(new ContextSuggestField("context_suggest_field", Collections.singletonList("type2"), "suggestion2", 3));
|
||||
document.add(new ContextSuggestField("context_suggest_field", Collections.singletonList("type3"), "suggestion3", 2));
|
||||
document.add(new ContextSuggestField("context_suggest_field", "suggestion1", 4, "type1"));
|
||||
document.add(new ContextSuggestField("context_suggest_field", "suggestion2", 3, "type2"));
|
||||
document.add(new ContextSuggestField("context_suggest_field", "suggestion3", 2, "type3"));
|
||||
iw.addDocument(document);
|
||||
|
||||
document = new Document();
|
||||
document.add(new SuggestField("suggest_field", "suggestion4", 1));
|
||||
document.add(new ContextSuggestField("context_suggest_field", Collections.singletonList("type4"), "suggestion4", 1));
|
||||
document.add(new ContextSuggestField("context_suggest_field", "suggestion4", 1, "type4"));
|
||||
iw.addDocument(document);
|
||||
|
||||
if (rarely()) {
|
||||
|
|
|
@ -17,8 +17,6 @@ package org.apache.lucene.search.suggest.document;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.analysis.MockAnalyzer;
|
||||
import org.apache.lucene.document.Document;
|
||||
|
@ -87,14 +85,14 @@ public class TestFuzzyCompletionQuery extends LuceneTestCase {
|
|||
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwcWithSuggestField(analyzer, "suggest_field"));
|
||||
Document document = new Document();
|
||||
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type1"), "sduggestion", 1));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type2"), "sudggestion", 1));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type3"), "sugdgestion", 1));
|
||||
document.add(new ContextSuggestField("suggest_field", "sduggestion", 1, "type1"));
|
||||
document.add(new ContextSuggestField("suggest_field", "sudggestion", 1, "type2"));
|
||||
document.add(new ContextSuggestField("suggest_field", "sugdgestion", 1, "type3"));
|
||||
iw.addDocument(document);
|
||||
|
||||
document = new Document();
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type4"), "suggdestion", 1));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type4"), "suggestion", 1));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggdestion", 1, "type4"));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion", 1, "type4"));
|
||||
iw.addDocument(document);
|
||||
|
||||
if (rarely()) {
|
||||
|
@ -123,14 +121,14 @@ public class TestFuzzyCompletionQuery extends LuceneTestCase {
|
|||
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwcWithSuggestField(analyzer, "suggest_field"));
|
||||
Document document = new Document();
|
||||
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type1"), "sduggestion", 1));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type2"), "sudggestion", 1));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type3"), "sugdgestion", 1));
|
||||
document.add(new ContextSuggestField("suggest_field", "sduggestion", 1, "type1"));
|
||||
document.add(new ContextSuggestField("suggest_field", "sudggestion", 1, "type2"));
|
||||
document.add(new ContextSuggestField("suggest_field", "sugdgestion", 1, "type3"));
|
||||
iw.addDocument(document);
|
||||
|
||||
document = new Document();
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type4"), "suggdestion", 1));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type4"), "suggestion", 1));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggdestion", 1, "type4"));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion", 1, "type4"));
|
||||
iw.addDocument(document);
|
||||
|
||||
if (rarely()) {
|
||||
|
|
|
@ -17,8 +17,6 @@ package org.apache.lucene.search.suggest.document;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.analysis.MockAnalyzer;
|
||||
import org.apache.lucene.document.Document;
|
||||
|
@ -84,14 +82,14 @@ public class TestRegexCompletionQuery extends LuceneTestCase {
|
|||
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwcWithSuggestField(analyzer, "suggest_field"));
|
||||
Document document = new Document();
|
||||
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type1"), "sduggestion", 5));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type2"), "sudggestion", 4));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type3"), "sugdgestion", 3));
|
||||
document.add(new ContextSuggestField("suggest_field", "sduggestion", 5, "type1"));
|
||||
document.add(new ContextSuggestField("suggest_field", "sudggestion", 4, "type2"));
|
||||
document.add(new ContextSuggestField("suggest_field", "sugdgestion", 3, "type3"));
|
||||
iw.addDocument(document);
|
||||
|
||||
document = new Document();
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type4"), "suggdestion", 2));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type4"), "suggestion", 1));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggdestion", 2, "type4"));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion", 1, "type4"));
|
||||
iw.addDocument(document);
|
||||
|
||||
if (rarely()) {
|
||||
|
@ -119,14 +117,14 @@ public class TestRegexCompletionQuery extends LuceneTestCase {
|
|||
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwcWithSuggestField(analyzer, "suggest_field"));
|
||||
Document document = new Document();
|
||||
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type1"), "sduggestion", 5));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type2"), "sudggestion", 4));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type3"), "sugdgestion", 3));
|
||||
document.add(new ContextSuggestField("suggest_field", "sduggestion", 5, "type1"));
|
||||
document.add(new ContextSuggestField("suggest_field", "sudggestion", 4, "type2"));
|
||||
document.add(new ContextSuggestField("suggest_field", "sugdgestion", 3, "type3"));
|
||||
iw.addDocument(document);
|
||||
|
||||
document = new Document();
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type4"), "suggdestion", 2));
|
||||
document.add(new ContextSuggestField("suggest_field", Collections.singletonList("type4"), "suggestion", 1));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggdestion", 2, "type4"));
|
||||
document.add(new ContextSuggestField("suggest_field", "suggestion", 1, "type4"));
|
||||
iw.addDocument(document);
|
||||
|
||||
if (rarely()) {
|
||||
|
|
Loading…
Reference in New Issue