org.apache.solr.client.solrj.response.SpellCheckResponse Java Examples

The following examples show how to use org.apache.solr.client.solrj.response.SpellCheckResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ItemSearchServiceLiveTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void whenSearchingWithKeywordWithMistake_thenSpellingSuggestionsShouldBeReturned() throws Exception {
    itemSearchService.index("hm0001", "Brand1 Washing Machine", "Home Appliances", 100f);
    itemSearchService.index("hm0002", "Brand1 Refrigerator", "Home Appliances", 300f);
    itemSearchService.index("hm0003", "Brand2 Ceiling Fan", "Home Appliances", 200f);
    itemSearchService.index("hm0004", "Brand2 Dishwasher", "Washing equipments", 250f);

    SolrQuery query = new SolrQuery();
    query.setQuery("hme");
    query.set("spellcheck", "on");
    QueryResponse response = solrClient.query(query);

    SpellCheckResponse spellCheckResponse = response.getSpellCheckResponse();

    assertEquals(false, spellCheckResponse.isCorrectlySpelled());

    Suggestion suggestion = spellCheckResponse.getSuggestions().get(0);

    assertEquals("hme", suggestion.getToken());

    List<String> alternatives = suggestion.getAlternatives();
    String alternative = alternatives.get(0);

    assertEquals("home", alternative);
}