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());
}
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;
}
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());
}
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;
}
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);
}
Aggregations