Example usage for org.apache.solr.common.params MapSolrParams get

List of usage examples for org.apache.solr.common.params MapSolrParams get

Introduction

In this page you can find the example usage for org.apache.solr.common.params MapSolrParams get.

Prototype

@Override
    public String get(String name) 

Source Link

Usage

From source file:edu.toronto.cs.cidb.solr.SolrScriptService.java

License:Open Source License

/**
 * Perform a search, falling back on the suggested spellchecked query if the original query fails to return any
 * results./*  w w  w .j av a2  s .co m*/
 * 
 * @param params the Solr parameters to use, should contain at least a value for the "q" parameter; use
 *        {@link #getSolrQuery(String, int, int)} to get the proper parameter expected by this method
 * @return the list of matching documents, empty if there are no matching terms
 */
private SolrDocumentList search(MapSolrParams params) {
    try {
        QueryResponse response = this.server.query(params);
        SolrDocumentList results = response.getResults();
        if (results.size() == 0 && !response.getSpellCheckResponse().isCorrectlySpelled()) {
            String suggestedQuery = response.getSpellCheckResponse().getCollatedResult();
            // The spellcheck doesn't preserve the identifiers, manually
            // correct this
            suggestedQuery = suggestedQuery.replaceAll("term_category:hip", "term_category:HP");
            MapSolrParams newParams = new MapSolrParams(
                    getSolrQuery(suggestedQuery, params.get(CommonParams.SORT),
                            params.getInt(CommonParams.ROWS, -1), params.getInt(CommonParams.START, 0)));
            return this.server.query(newParams).getResults();
        } else {
            return results;
        }
    } catch (SolrServerException ex) {
        this.logger.error("Failed to search: {}", ex.getMessage(), ex);
    }
    return null;
}