Search in sources :

Example 1 with Entry

use of org.elasticsearch.search.suggest.term.TermSuggestion.Entry in project xp by enonic.

the class SuggestionsFactoryTest method testTermSuggestion.

@Test
public void testTermSuggestion() {
    final Option option1 = Mockito.mock(Option.class);
    Mockito.when(option1.getText()).thenReturn(new Text("option1"));
    Mockito.when(option1.getScore()).thenReturn(1.0f);
    Mockito.when(option1.getFreq()).thenReturn(3);
    final Entry entry1 = Mockito.mock(Entry.class);
    Mockito.when(entry1.getLength()).thenReturn(2);
    Mockito.when(entry1.getOffset()).thenReturn(1);
    Mockito.when(entry1.getText()).thenReturn(new Text("entry1"));
    Mockito.when(entry1.getOptions()).thenReturn(List.of(option1));
    final TermSuggestion termSuggestion1 = Mockito.mock(TermSuggestion.class);
    Mockito.when(termSuggestion1.getName()).thenReturn("suggestion1");
    Mockito.when(termSuggestion1.getEntries()).thenReturn(List.of(entry1));
    final Suggest suggest = new Suggest(List.of(termSuggestion1));
    final Suggestions suggestions = SuggestionsFactory.create(suggest);
    assertNotNull(suggestions);
    assertFalse(suggestions.isEmpty());
    final com.enonic.xp.suggester.TermSuggestion resultSuggestion = (com.enonic.xp.suggester.TermSuggestion) suggestions.get("suggestion1");
    assertFalse(resultSuggestion.getEntries().isEmpty());
    final TermSuggestionEntry resultEntry = resultSuggestion.getEntries().get(0);
    assertEquals("entry1", resultEntry.getText());
    assertEquals(2L, resultEntry.getLength().longValue());
    assertEquals(1L, resultEntry.getOffset().longValue());
    final TermSuggestionOption resultOption = resultEntry.getOptions().get(0);
    assertEquals("option1", resultOption.getText());
    assertEquals(3L, resultOption.getFreq().longValue());
    assertEquals(1.0f, resultOption.getScore(), 1e-14);
}
Also used : TermSuggestionEntry(com.enonic.xp.suggester.TermSuggestionEntry) Text(org.elasticsearch.common.text.Text) TermSuggestionOption(com.enonic.xp.suggester.TermSuggestionOption) Suggest(org.elasticsearch.search.suggest.Suggest) Suggestions(com.enonic.xp.suggester.Suggestions) Entry(org.elasticsearch.search.suggest.term.TermSuggestion.Entry) TermSuggestionEntry(com.enonic.xp.suggester.TermSuggestionEntry) TermSuggestion(org.elasticsearch.search.suggest.term.TermSuggestion) Option(org.elasticsearch.search.suggest.term.TermSuggestion.Entry.Option) TermSuggestionOption(com.enonic.xp.suggester.TermSuggestionOption) Test(org.junit.jupiter.api.Test)

Aggregations

Suggestions (com.enonic.xp.suggester.Suggestions)1 TermSuggestionEntry (com.enonic.xp.suggester.TermSuggestionEntry)1 TermSuggestionOption (com.enonic.xp.suggester.TermSuggestionOption)1 Text (org.elasticsearch.common.text.Text)1 Suggest (org.elasticsearch.search.suggest.Suggest)1 TermSuggestion (org.elasticsearch.search.suggest.term.TermSuggestion)1 Entry (org.elasticsearch.search.suggest.term.TermSuggestion.Entry)1 Option (org.elasticsearch.search.suggest.term.TermSuggestion.Entry.Option)1 Test (org.junit.jupiter.api.Test)1