use of org.opengrok.suggest.query.SuggesterPrefixQuery in project OpenGrok by OpenGrok.
the class SuggesterSearcherTest method suggesterPrefixQueryTest.
@Test
public void suggesterPrefixQueryTest() {
List<LookupResultItem> suggestions = searcher.suggest(new TermQuery(new Term("test", "test")), "test", new SuggesterPrefixQuery(new Term("test", "o")), k -> 0);
List<String> tokens = suggestions.stream().map(LookupResultItem::getPhrase).collect(Collectors.toList());
assertThat(tokens, contains("opengrok"));
}
use of org.opengrok.suggest.query.SuggesterPrefixQuery in project OpenGrok by OpenGrok.
the class SuggesterTest method testSimpleSuggestions.
@Test
public void testSimpleSuggestions() throws IOException {
SuggesterTestData t = initSuggester();
Suggester.NamedIndexReader ir = t.getNamedIndexReader();
List<LookupResultItem> res = t.s.search(Collections.singletonList(ir), new SuggesterPrefixQuery(new Term("test", "t")), null).getItems();
assertThat(res.stream().map(LookupResultItem::getPhrase).collect(Collectors.toList()), containsInAnyOrder("term1", "term2", "term3"));
t.close();
}
use of org.opengrok.suggest.query.SuggesterPrefixQuery in project OpenGrok by OpenGrok.
the class SuggesterQueryParser method newTermQuery.
@Override
protected Query newTermQuery(final Term term, float boost) {
if (term.text().contains(identifier)) {
Query q = new SuggesterPrefixQuery(replaceIdentifier(term, identifier));
this.suggesterQuery = (SuggesterPrefixQuery) q;
if (boost != DEFAULT_BOOST) {
q = new BoostQuery(q, boost);
}
return q;
}
return super.newTermQuery(term, boost);
}
use of org.opengrok.suggest.query.SuggesterPrefixQuery in project OpenGrok by OpenGrok.
the class SuggesterTest method testRefresh.
@Test
public void testRefresh() throws IOException {
SuggesterTestData t = initSuggester();
addText(t.getIndexDirectory(), "a1 a2");
t.s.rebuild(Collections.singleton(t.getNamedIndexDir()));
Suggester.NamedIndexReader ir = t.getNamedIndexReader();
List<LookupResultItem> res = t.s.search(Collections.singletonList(ir), new SuggesterPrefixQuery(new Term("test", "a")), null).getItems();
assertThat(res.stream().map(LookupResultItem::getPhrase).collect(Collectors.toList()), containsInAnyOrder("a1", "a2"));
t.close();
}
use of org.opengrok.suggest.query.SuggesterPrefixQuery in project OpenGrok by OpenGrok.
the class SuggesterTest method testIndexChangedWhileOffline.
@Test
public void testIndexChangedWhileOffline() throws IOException {
SuggesterTestData t = initSuggester();
t.s.close();
addText(t.getIndexDirectory(), "a1 a2");
t.s = new Suggester(t.suggesterDir.toFile(), 10, Duration.ofMinutes(1), false, true, Collections.singleton("test"), Integer.MAX_VALUE, Runtime.getRuntime().availableProcessors(), registry);
t.s.init(Collections.singleton(t.getNamedIndexDir()));
await().atMost(2, TimeUnit.SECONDS).until(() -> getSuggesterProjectDataSize(t.s) == 1);
Suggester.NamedIndexReader ir = t.getNamedIndexReader();
List<LookupResultItem> res = t.s.search(Collections.singletonList(ir), new SuggesterPrefixQuery(new Term("test", "a")), null).getItems();
assertThat(res.stream().map(LookupResultItem::getPhrase).collect(Collectors.toList()), containsInAnyOrder("a1", "a2"));
t.close();
}
Aggregations