Changeset 4384


Ignore:
Timestamp:
01/29/14 13:22:07 (10 years ago)
Author:
twagoo
Message:

fixed potential null pointer exception in autocomplete dao

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vlo/branches/vlo-2.18/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/dao/AutoCompleteDao.java

    r2768 r4384  
    1111/**
    1212 * DAO that delivers suggestions for incomplete terms (autocomplete function)
    13  * 
     13 *
    1414 * @author Thomas Eckart
    1515 *
    1616 */
    1717public 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         }
     18
     19    /**
     20     * Returns list of suggestions for incomplete input (used for autocomplete
     21     * function)
     22     *
     23     * @param input user input
     24     * @return list of suggestions
     25     */
     26    public List<String> getChoices(String input) {
     27        List<String> choices = new ArrayList<String>();
     28
     29        if (input != null) {
     30            SolrQuery query = new SolrQuery();
     31            query.setQuery(input.toLowerCase());
     32            query.setQueryType("/suggest");
     33            QueryResponse response = fireQuery(query);
     34            if (response.getSpellCheckResponse() != null) {
     35                List<Suggestion> suggestions = response.getSpellCheckResponse().getSuggestions();
     36                if (suggestions.size() > 0) {
     37                    Iterator<String> iter = suggestions.get(0).getAlternatives().iterator();
     38                    while (iter.hasNext()) {
     39                        choices.add(iter.next());
     40                    }
     41                }
     42            }
     43        }
     44
     45        return choices;
     46    }
    4347}
Note: See TracChangeset for help on using the changeset viewer.