Example usage for org.apache.solr.client.solrj SolrQuery setParam

List of usage examples for org.apache.solr.client.solrj SolrQuery setParam

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj SolrQuery setParam.

Prototype

public SolrQuery setParam(String name, boolean value) 

Source Link

Usage

From source file:uk.co.flax.biosolr.ontology.search.solr.SolrDocumentSearch.java

License:Apache License

@Override
public ResultsList<Document> searchDocuments(String term, int start, int rows, List<String> additionalFields,
        List<String> filters) throws SearchEngineException {
    ResultsList<Document> results;

    try {//from   www. j a  v a  2  s  . co  m
        SolrQuery query = new SolrQuery(term);
        query.setStart(start);
        query.setRows(rows);
        query.setRequestHandler(config.getDocumentRequestHandler());
        List<String> queryFields = new ArrayList<>(DEFAULT_SEARCH_FIELDS);
        if (additionalFields != null) {
            queryFields.addAll(additionalFields);
        }
        if (filters != null) {
            query.addFilterQuery(filters.toArray(new String[filters.size()]));
        }
        query.setParam(DisMaxParams.QF, queryFields.toArray(new String[queryFields.size()]));

        LOGGER.debug("Query: {}", query);

        QueryResponse response = server.query(query);
        List<Document> docs;
        long total = 0;

        if (response.getGroupResponse() != null) {
            docs = new ArrayList<>(rows);
            GroupResponse gResponse = response.getGroupResponse();
            for (GroupCommand gCommand : gResponse.getValues()) {
                total += gCommand.getNGroups();
                for (Group group : gCommand.getValues()) {
                    docs.addAll(server.getBinder().getBeans(Document.class, group.getResult()));
                }
            }
        } else if (response.getResults().getNumFound() == 0) {
            docs = new ArrayList<>();
        } else {
            docs = response.getBeans(Document.class);
            total = response.getResults().getNumFound();
        }

        results = new ResultsList<>(docs, start, (start / rows), total);
    } catch (SolrServerException | IOException e) {
        throw new SearchEngineException(e);
    }

    return results;
}