Last change
on this file since 2641 was
2641,
checked in by keeloo, 11 years ago
|
ranches
|
-
Property svn:mime-type set to
text/plain
|
File size:
1.2 KB
|
Line | |
---|
1 | package eu.clarin.cmdi.vlo.dao; |
---|
2 | |
---|
3 | import java.util.ArrayList; |
---|
4 | import java.util.Iterator; |
---|
5 | import java.util.List; |
---|
6 | |
---|
7 | import org.apache.solr.client.solrj.SolrQuery; |
---|
8 | import org.apache.solr.client.solrj.response.QueryResponse; |
---|
9 | import org.apache.solr.client.solrj.response.SpellCheckResponse.Suggestion; |
---|
10 | |
---|
11 | /** |
---|
12 | * DAO that delivers suggestions for incomplete terms (autocomplete function) |
---|
13 | * |
---|
14 | * @author Thomas Eckart |
---|
15 | * |
---|
16 | */ |
---|
17 | public class AutoCompleteDao extends SolrDao { |
---|
18 | |
---|
19 | /** |
---|
20 | * Returns list of suggestions for incomplete input (used for autocomplete function) |
---|
21 | * @param input user input |
---|
22 | * @return list of suggestions |
---|
23 | */ |
---|
24 | public List<String> getChoices(String input) { |
---|
25 | List<String> choices = new ArrayList<String>(); |
---|
26 | |
---|
27 | SolrQuery query = new SolrQuery(); |
---|
28 | query.setQuery(input.toLowerCase()); |
---|
29 | query.setQueryType("/suggest"); |
---|
30 | QueryResponse response = fireQuery(query); |
---|
31 | if(response.getSpellCheckResponse() != null) { |
---|
32 | List<Suggestion> suggestions = response.getSpellCheckResponse().getSuggestions(); |
---|
33 | if(suggestions.size() > 0) { |
---|
34 | Iterator<String> iter = suggestions.get(0).getAlternatives().iterator(); |
---|
35 | while(iter.hasNext()) { |
---|
36 | choices.add(iter.next()); |
---|
37 | } |
---|
38 | } |
---|
39 | } |
---|
40 | |
---|
41 | return choices; |
---|
42 | } |
---|
43 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.