I've already optimized pagination of mysql data by including the last ID from the previous page in the query so instead of having "LIMIT 200,20" it would be "WHERE id < $last_id_from_previous_page LIMIT 20".
This has dramatically sped up pagination of mysql data. Now I'm looking to something similar for my solr queries and I'm wonderi开发者_JAVA技巧ng if that's even possible.
Using my solr php library I do a search like so:
$solr->search($search_term, $start, $limit, $additionalParameters);
Can I specify that the ID has to be smaller than a certain number within the search term parameter itself? Something like "cats AND [id < 200]".. ? Would this give me a performance gain with solr as it does with mysql?
SOLR supports specifying a start row, and the number of rows to return. This is what people use to do pagination. How to manage "paging" with Solr?
If your SOLR search library doesn't support this, then you should go direct to the HTTP search interface and talk to SOLR directly.
Only if the field you are filtering by is also the field you are sorting by AND that field supports the concept of "<" comparison.
For example, if you sorted by a last name alphabetically, it may be difficult to filter out the first 20. Where as if you sorted by a number that represented a date/time, you may be able to pull this off.
Realistically, there is no numeric field that I'm aware of that is associated with the document for just that one search.
EDIT: I would ask a deeper question ... Are you sure you need to optimize pagination this heavily? If your searches are well tuned for your users, rarely will they need to go past the first or second page of results to find what they are looking for. Solr will already keep the document ids in the cache from the initial query, so this should already perform fairly well.
精彩评论