将SolrdocumentList更改转换为List

时间:2017-05-17 02:04:29

标签: solr solrj

例如,我有solrdocmentlist,其中包含3个字段,即id,type和description。但是现在我想将返回的solrdocmentlist更改为List,我该怎么办?下面的代码是返回的solrdocmentlist,如何将文档更改为List?

public SolrDocumentList searchSolr(String Keyword)
        throws MalformedURLException, SolrServerException {
    String _LOC = "[W_search: searchSolr]";

    HttpSolrServer solr = new HttpSolrServer(
            "http://localhost:8983/solr/collection1");
    SolrQuery query = new SolrQuery();
    query.set("q", "description:" + Keyword);
    query.setStart(0);
    query.setRows(6);
    QueryResponse response = solr.query(query);
    SolrDocumentList docs = response.getResults();
    return docs;
}

1 个答案:

答案 0 :(得分:0)

由于SolrDocumentList扩展了ArrayList<SolrDocument>,后者实现了List

List<SolrDocument> list = docs;应该可以解决问题。