Search in sources :

Example 1 with TermSuggestionQuery

use of com.enonic.xp.query.suggester.TermSuggestionQuery in project xp by enonic.

the class TermSuggestionQueryTest method testBuilder.

@Test
public void testBuilder() {
    final TermSuggestionQuery query = TermSuggestionQuery.create("queryName").field("category").text("value").analyzer("analyzer").size(1).maxEdits(2).prefixLength(3).minWordLength(4).maxInspections(5).minDocFreq(6f).maxTermFreq(7f).sort(TermSuggestionQuery.Sort.FREQUENCY).suggestMode(TermSuggestionQuery.SuggestMode.ALWAYS).stringDistance(TermSuggestionQuery.StringDistance.INTERNAL).build();
    assertEquals("queryName", query.getName());
    assertEquals("category", query.getField());
    assertEquals("value", query.getText());
    assertEquals("analyzer", query.getAnalyzer());
    assertEquals((Integer) 1, query.getSize());
    assertEquals((Integer) 2, query.getMaxEdits());
    assertEquals((Integer) 3, query.getPrefixLength());
    assertEquals((Integer) 4, query.getMinWordLength());
    assertEquals((Integer) 5, query.getMaxInspections());
    assertEquals(6F, query.getMinDocFreq(), 0.0);
    assertEquals(7F, query.getMaxTermFreq(), 0.0);
    assertEquals(TermSuggestionQuery.Sort.FREQUENCY, query.getSort());
    assertEquals(TermSuggestionQuery.SuggestMode.ALWAYS, query.getSuggestMode());
    assertEquals(TermSuggestionQuery.StringDistance.INTERNAL, query.getStringDistance());
}
Also used : TermSuggestionQuery(com.enonic.xp.query.suggester.TermSuggestionQuery) Test(org.junit.jupiter.api.Test)

Example 2 with TermSuggestionQuery

use of com.enonic.xp.query.suggester.TermSuggestionQuery in project xp by enonic.

the class TermSuggestionQueryBuilderFactory method create.

public TermSuggestionBuilder create(final TermSuggestionQuery suggestionQuery) {
    final String field = fieldNameResolver.resolve(suggestionQuery.getField(), IndexValueType.ANALYZED);
    final TermSuggestionBuilder builder = new TermSuggestionBuilder(suggestionQuery.getName()).field(field).text(suggestionQuery.getText());
    final Integer size = suggestionQuery.getSize();
    final String analyzer = suggestionQuery.getAnalyzer();
    final TermSuggestionQuery.Sort sort = suggestionQuery.getSort();
    final TermSuggestionQuery.SuggestMode suggestMode = suggestionQuery.getSuggestMode();
    final Integer maxEdits = suggestionQuery.getMaxEdits();
    final Integer prefixLength = suggestionQuery.getPrefixLength();
    final Integer minWordLength = suggestionQuery.getMinWordLength();
    final Integer maxInspections = suggestionQuery.getMaxInspections();
    final Float minDocFreq = suggestionQuery.getMinDocFreq();
    final Float maxTermFreq = suggestionQuery.getMaxTermFreq();
    final TermSuggestionQuery.StringDistance stringDistance = suggestionQuery.getStringDistance();
    if (size != null) {
        builder.size(size);
    }
    if (analyzer != null) {
        builder.analyzer(analyzer);
    }
    if (sort != null) {
        builder.sort(sort.value());
    }
    if (suggestMode != null) {
        builder.suggestMode(suggestMode.value());
    }
    if (maxEdits != null) {
        builder.maxEdits(maxEdits);
    }
    if (prefixLength != null) {
        builder.prefixLength(prefixLength);
    }
    if (minWordLength != null) {
        builder.minWordLength(minWordLength);
    }
    if (maxInspections != null) {
        builder.maxInspections(maxInspections);
    }
    if (minDocFreq != null) {
        builder.minDocFreq(minDocFreq);
    }
    if (maxTermFreq != null) {
        builder.maxTermFreq(maxTermFreq);
    }
    if (stringDistance != null) {
        builder.stringDistance(stringDistance.value());
    }
    return builder;
}
Also used : TermSuggestionBuilder(org.elasticsearch.search.suggest.term.TermSuggestionBuilder) TermSuggestionQuery(com.enonic.xp.query.suggester.TermSuggestionQuery)

Example 3 with TermSuggestionQuery

use of com.enonic.xp.query.suggester.TermSuggestionQuery in project xp by enonic.

the class SuggestionQueryBuilderFactoryTest method create.

@Test
public void create() {
    final TermSuggestionQuery query = TermSuggestionQuery.create("queryName").field("category").text("value").analyzer("analyzer").size(1).maxEdits(2).prefixLength(3).minWordLength(4).maxInspections(5).minDocFreq(6f).maxTermFreq(7f).sort(TermSuggestionQuery.Sort.FREQUENCY).suggestMode(TermSuggestionQuery.SuggestMode.ALWAYS).stringDistance(TermSuggestionQuery.StringDistance.INTERNAL).build();
    final Set<SuggestBuilder.SuggestionBuilder> suggestionBuilder = suggestionQueryBuilderFactory.create(SuggestionQueries.create().add(query).build());
    assertNotNull(suggestionBuilder);
    assertEquals(1, suggestionBuilder.size());
    assertEquals(TermSuggestionBuilder.class, suggestionBuilder.toArray()[0].getClass());
}
Also used : TermSuggestionQuery(com.enonic.xp.query.suggester.TermSuggestionQuery) TermSuggestionBuilder(org.elasticsearch.search.suggest.term.TermSuggestionBuilder) Test(org.junit.jupiter.api.Test)

Example 4 with TermSuggestionQuery

use of com.enonic.xp.query.suggester.TermSuggestionQuery in project xp by enonic.

the class SuggestionQueryBuilderFactory method doCreate.

private Set<SuggestBuilder.SuggestionBuilder> doCreate(final SuggestionQueries suggestionQueries) {
    Set<SuggestBuilder.SuggestionBuilder> suggestionBuilders = new HashSet<>();
    for (final SuggestionQuery suggestionQuery : suggestionQueries) {
        final SuggestBuilder.SuggestionBuilder suggestionBuilder;
        if (suggestionQuery instanceof TermSuggestionQuery) {
            suggestionBuilder = new TermSuggestionQueryBuilderFactory(fieldNameResolver).create((TermSuggestionQuery) suggestionQuery);
        } else {
            throw new IllegalArgumentException("Unexpected suggestion type: " + suggestionQuery.getClass());
        }
        suggestionBuilders.add(suggestionBuilder);
    }
    return suggestionBuilders;
}
Also used : SuggestBuilder(org.elasticsearch.search.suggest.SuggestBuilder) TermSuggestionQuery(com.enonic.xp.query.suggester.TermSuggestionQuery) SuggestionQuery(com.enonic.xp.query.suggester.SuggestionQuery) TermSuggestionQuery(com.enonic.xp.query.suggester.TermSuggestionQuery) HashSet(java.util.HashSet)

Example 5 with TermSuggestionQuery

use of com.enonic.xp.query.suggester.TermSuggestionQuery in project xp by enonic.

the class TermSuggestionQueryBuilderFactoryTest method create.

@Test
public void create() {
    final TermSuggestionQuery query = TermSuggestionQuery.create("queryName").field("category").text("value").analyzer("analyzer").size(1).maxEdits(2).prefixLength(3).minWordLength(4).maxInspections(5).minDocFreq(6f).maxTermFreq(7f).sort(TermSuggestionQuery.Sort.FREQUENCY).suggestMode(TermSuggestionQuery.SuggestMode.ALWAYS).stringDistance(TermSuggestionQuery.StringDistance.INTERNAL).build();
    final TermSuggestionBuilder suggestionBuilder = termSuggestionQueryBuilderFactory.create(query);
    assertNotNull(suggestionBuilder);
}
Also used : TermSuggestionBuilder(org.elasticsearch.search.suggest.term.TermSuggestionBuilder) TermSuggestionQuery(com.enonic.xp.query.suggester.TermSuggestionQuery) Test(org.junit.jupiter.api.Test)

Aggregations

TermSuggestionQuery (com.enonic.xp.query.suggester.TermSuggestionQuery)6 Test (org.junit.jupiter.api.Test)4 TermSuggestionBuilder (org.elasticsearch.search.suggest.term.TermSuggestionBuilder)3 SuggestionQueries (com.enonic.xp.query.suggester.SuggestionQueries)1 SuggestionQuery (com.enonic.xp.query.suggester.SuggestionQuery)1 HashSet (java.util.HashSet)1 SuggestBuilder (org.elasticsearch.search.suggest.SuggestBuilder)1