use of org.apache.lucene.search.suggest.document.TestSuggestField.Entry in project lucene-solr by apache.
the class TestContextQuery method testSameSuggestionMultipleContext.
@Test
public void testSameSuggestionMultipleContext() throws Exception {
Analyzer analyzer = new MockAnalyzer(random());
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwcWithSuggestField(analyzer, "suggest_field"));
Document document = new Document();
document.add(new ContextSuggestField("suggest_field", "suggestion", 4, "type1", "type2", "type3"));
iw.addDocument(document);
document = new Document();
document.add(new ContextSuggestField("suggest_field", "suggestion", 1, "type4"));
iw.addDocument(document);
if (rarely()) {
iw.commit();
}
DirectoryReader reader = iw.getReader();
SuggestIndexSearcher suggestIndexSearcher = new SuggestIndexSearcher(reader);
ContextQuery query = new ContextQuery(new PrefixCompletionQuery(analyzer, new Term("suggest_field", "sugg")));
query.addContext("type1", 10);
query.addContext("type2", 2);
query.addContext("type3", 3);
query.addContext("type4", 4);
TopSuggestDocs suggest = suggestIndexSearcher.suggest(query, 5, false);
assertSuggestions(suggest, new Entry("suggestion", "type1", 4 * 10), new Entry("suggestion", "type3", 4 * 3), new Entry("suggestion", "type2", 4 * 2), new Entry("suggestion", "type4", 1 * 4));
reader.close();
iw.close();
}
use of org.apache.lucene.search.suggest.document.TestSuggestField.Entry in project lucene-solr by apache.
the class TestContextSuggestField method testCompletionAnalyzer.
@Test
public void testCompletionAnalyzer() throws Exception {
CompletionAnalyzer completionAnalyzer = new CompletionAnalyzer(new StandardAnalyzer(), true, true);
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwcWithSuggestField(completionAnalyzer, "suggest_field"));
Document document = new Document();
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", "suggestion4", 1, "type4"));
iw.addDocument(document);
if (rarely()) {
iw.commit();
}
DirectoryReader reader = iw.getReader();
SuggestIndexSearcher suggestIndexSearcher = new SuggestIndexSearcher(reader);
ContextQuery query = new ContextQuery(new PrefixCompletionQuery(completionAnalyzer, new Term("suggest_field", "sugg")));
TopSuggestDocs suggest = suggestIndexSearcher.suggest(query, 4, false);
assertSuggestions(suggest, new Entry("suggestion1", "type1", 4), new Entry("suggestion2", "type2", 3), new Entry("suggestion3", "type3", 2), new Entry("suggestion4", "type4", 1));
query.addContext("type1");
suggest = suggestIndexSearcher.suggest(query, 4, false);
assertSuggestions(suggest, new Entry("suggestion1", "type1", 4));
reader.close();
iw.close();
}
Aggregations