You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by "Olson, Ron" <RO...@lbpc.com> on 2010/11/04 20:22:07 UTC

Using setStart in solrj

Hi all-

First, thanks to all the folks to have helped me so far getting the hang of Solr; I promise to give back when I think my contributions will be useful :)

I am at the point where I'm trying to return results back from a search in a war file, using Java with solrj. On the result page of the website I'd want to limit the actual results to probably around 20 or so, with the usual "next/prev page" paradigm. The issue I've been wrestling with is keeping the SolrQuery object around so that I don't need to transmit the entire thing back to the client, especially if they search for something like "truck", which could return a lot of results.

I was thinking that one solution would be to do a "query.setRows(20);" for the query, then return the results back with some sort of an identifier so that on subsequent queries, I could also include "query.setStart(someCounter + 1);" to get the next set of 20. In theory, that would work at the cost of having to re-execute the query.

I've been looking for information about setStart() and haven't found much more than Javadoc that says "sets the starting row for the result set". My question is, how do I know what the starting row is? Maybe, based on the search parameters, it will always return the results in an implicit order in which case is it just like executing a fixed query in a database and then grabbing the next 20 rows from the result set? Because the user would be pressing the prev/next buttons, even though the query is being re-executed, the parameters would not be changing.

That's the theory, anyway. It seems excessive to keep executing the same query over and over again just because the user wants to see the next set of results, especially if the original SolrQuery object has them all, but maybe that's just what needs to be done, given the stateless nature of the web.

Any info on this method/strategy would be most appreciated.

Thanks,

Ron

DISCLAIMER: This electronic message, including any attachments, files or documents, is intended only for the addressee and may contain CONFIDENTIAL, PROPRIETARY or LEGALLY PRIVILEGED information.  If you are not the intended recipient, you are hereby notified that any use, disclosure, copying or distribution of this message or any of the information included in or with it is  unauthorized and strictly prohibited.  If you have received this message in error, please notify the sender immediately by reply e-mail and permanently delete and destroy this message and its attachments, along with any copies thereof. This message does not create any contractual obligation on behalf of the sender or Law Bulletin Publishing Company.
Thank you.

Re: Using setStart in solrj

Posted by Peter Karich <pe...@yahoo.de>.
  Hi Ron,

>  how do I know what the starting row

Always 0.

>  especially if the original SolrQuery object has them all

thats the point. solr will normally cache it for you. This is your friend:
<queryResultWindowSize>40</queryResultWindowSize>
<!-- Maximum number of documents to cache for any entry in the
        queryResultCache. -->

just try it first with http to get an impression what start is good for:
it just sets the starting doc for the current query.
E.g. you have a very complicated query ala
select?q=xy&param1=...&param2=...&paramN=...&rows=20&start=0

the next *page* would be
select?q=xy&param1=...&param2=...&paramN=...&rows=20&start=20

(newStart=oldStart+rows)

(To get the next page you'll need to keep the params either in the 
session or 'encoded' within the url.)

Just try and ask if you need more info :-)

Regards,
Peter.

> Hi all-
>
> First, thanks to all the folks to have helped me so far getting the hang of Solr; I promise to give back when I think my contributions will be useful :)
>
> I am at the point where I'm trying to return results back from a search in a war file, using Java with solrj. On the result page of the website I'd want to limit the actual results to probably around 20 or so, with the usual "next/prev page" paradigm. The issue I've been wrestling with is keeping the SolrQuery object around so that I don't need to transmit the entire thing back to the client, especially if they search for something like "truck", which could return a lot of results.
>
> I was thinking that one solution would be to do a "query.setRows(20);" for the query, then return the results back with some sort of an identifier so that on subsequent queries, I could also include "query.setStart(someCounter + 1);" to get the next set of 20. In theory, that would work at the cost of having to re-execute the query.
>
> I've been looking for information about setStart() and haven't found much more than Javadoc that says "sets the starting row for the result set". My question is, how do I know what the starting row is? Maybe, based on the search parameters, it will always return the results in an implicit order in which case is it just like executing a fixed query in a database and then grabbing the next 20 rows from the result set? Because the user would be pressing the prev/next buttons, even though the query is being re-executed, the parameters would not be changing.
>
> That's the theory, anyway. It seems excessive to keep executing the same query over and over again just because the user wants to see the next set of results, especially if the original SolrQuery object has them all, but maybe that's just what needs to be done, given the stateless nature of the web.
>
> Any info on this method/strategy would be most appreciated.
>
> Thanks,
>
> Ron
>
> DISCLAIMER: This electronic message, including any attachments, files or documents, is intended only for the addressee and may contain CONFIDENTIAL, PROPRIETARY or LEGALLY PRIVILEGED information.  If you are not the intended recipient, you are hereby notified that any use, disclosure, copying or distribution of this message or any of the information included in or with it is  unauthorized and strictly prohibited.  If you have received this message in error, please notify the sender immediately by reply e-mail and permanently delete and destroy this message and its attachments, along with any copies thereof. This message does not create any contractual obligation on behalf of the sender or Law Bulletin Publishing Company.
> Thank you.
>


-- 
http://jetwick.com twitter search prototype