Search code examples
solrsolrj

Convert SolrdocumentList change to List


For example , i have solrdocmentlist which contain 3 field , which is id ,type and description . But now i want to change the returned solrdocmentlist to List, how can i do? The code below is the solrdocmentlist returned ,how can i change the docs to the 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;
}

Solution

  • Since SolrDocumentList extends ArrayList<SolrDocument> which implements List,

    List<SolrDocument> list = docs; should do the trick.