How to get all results from solr query?

后端 未结 8 900
温柔的废话
温柔的废话 2021-01-01 10:36

I executed some query like \"Address:Jack*\". It show numFound = 5214 and display 100 documents in results page(I changed default display results f

8条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-01 11:14

    What you should do is to first create a SolrQuery shown below and set the number of documents you want to fetch in a batch.

    int lastResult=0; //this is for processing the future batch
    
    String query = "id:[ lastResult TO *]"; // just considering id for the sake of simplicity
    
    SolrQuery solrQuery = new SolrQuery(query).setRows(500); //setRows will set the required batch, you can change this to whatever size you want.
    
    SolrDocumentList results = solrClient.query(solrQuery).getResults(); //execute this statement
    

    Here I am considering an example of search by id, you can replace it with any of your parameter to search upon.

    The "lastResult" is the variable you can change after execution of the first 500 records(500 is the batch size) and set it to the last id got from the results.

    This will help you execute the next batch starting with last result from previous batch.

    Hope this helps. Shoot up a comment below if you need any clarification.

提交回复
热议问题