Search in sources :

Example 1 with SuggesterPrefixQuery

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"));
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) SuggesterPrefixQuery(org.opengrok.suggest.query.SuggesterPrefixQuery) Term(org.apache.lucene.index.Term) Test(org.junit.jupiter.api.Test)

Example 2 with SuggesterPrefixQuery

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();
}
Also used : SuggesterPrefixQuery(org.opengrok.suggest.query.SuggesterPrefixQuery) Term(org.apache.lucene.index.Term) Test(org.junit.jupiter.api.Test)

Example 3 with SuggesterPrefixQuery

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);
}
Also used : Query(org.apache.lucene.search.Query) SuggesterRegexpQuery(org.opengrok.suggest.query.SuggesterRegexpQuery) SuggesterRangeQuery(org.opengrok.suggest.query.SuggesterRangeQuery) SuggesterFuzzyQuery(org.opengrok.suggest.query.SuggesterFuzzyQuery) SuggesterPhraseQuery(org.opengrok.suggest.query.SuggesterPhraseQuery) SuggesterPrefixQuery(org.opengrok.suggest.query.SuggesterPrefixQuery) FuzzyQuery(org.apache.lucene.search.FuzzyQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) SuggesterQuery(org.opengrok.suggest.query.SuggesterQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) SuggesterWildcardQuery(org.opengrok.suggest.query.SuggesterWildcardQuery) BoostQuery(org.apache.lucene.search.BoostQuery) SuggesterPrefixQuery(org.opengrok.suggest.query.SuggesterPrefixQuery) BoostQuery(org.apache.lucene.search.BoostQuery)

Example 4 with SuggesterPrefixQuery

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();
}
Also used : SuggesterPrefixQuery(org.opengrok.suggest.query.SuggesterPrefixQuery) Term(org.apache.lucene.index.Term) Test(org.junit.jupiter.api.Test)

Example 5 with SuggesterPrefixQuery

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();
}
Also used : SuggesterPrefixQuery(org.opengrok.suggest.query.SuggesterPrefixQuery) Term(org.apache.lucene.index.Term) Test(org.junit.jupiter.api.Test)

Aggregations

SuggesterPrefixQuery (org.opengrok.suggest.query.SuggesterPrefixQuery)7 Term (org.apache.lucene.index.Term)5 Test (org.junit.jupiter.api.Test)4 SuggesterWildcardQuery (org.opengrok.suggest.query.SuggesterWildcardQuery)2 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 BoostQuery (org.apache.lucene.search.BoostQuery)1 FuzzyQuery (org.apache.lucene.search.FuzzyQuery)1 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1 Query (org.apache.lucene.search.Query)1 TermQuery (org.apache.lucene.search.TermQuery)1 SuggesterFuzzyQuery (org.opengrok.suggest.query.SuggesterFuzzyQuery)1 SuggesterPhraseQuery (org.opengrok.suggest.query.SuggesterPhraseQuery)1 SuggesterQuery (org.opengrok.suggest.query.SuggesterQuery)1 SuggesterRangeQuery (org.opengrok.suggest.query.SuggesterRangeQuery)1 SuggesterRegexpQuery (org.opengrok.suggest.query.SuggesterRegexpQuery)1