You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@lucene.apache.org by Chris Hostetter <ho...@fucit.org> on 2009/04/04 00:11:46 UTC

Re: hwo to get paged search result

: The problem comes as in this procedure i has to set the third parameter n
: and as a result, when user click the last page link, exception will be
: thrown when the total number of search results excesses the *n* i specified
: in the program. How can i overcome this problem?

you're going to need to change "n" ... typically people just use something 
like... 
	int n = DOCS_PER_PAGE * page_num

have you looked at the Lucene Demo code?  it has a more complex example of 
doing a paginated search (grep for doPagingSearch) ...

http://svn.apache.org/viewvc/lucene/java/trunk/src/demo/org/apache/lucene/demo/SearchFiles.java?view=markup


: I've posted this problem twice and seen no reply. Could anyone offer a
: hand?  Thanks.

You should consider posting to the java-user@lucene mailing list which 
is specificly focused on discussions of using hte java API ... 
general@lucene is a broader list for discussions about the braoder Lucene 
project, or as a getting started point for people who aren't even sure 
which Lucene technology (PyLucene, Lucene-Java, Solr, Mahout, Nutch, 
etc...) might be useful for them.




-Hoss


Re: hwo to get paged search result

Posted by 王巍巍 <ww...@gmail.com>.
In my project, we allow the user to click the last page link, so if the n
specified is less than the totalHits, exception will be thrown.
I've changed to my code to like this

        set N to default number of docs to be retrieved
        Query query = qp.parse(keyword);
        Filter filter = getQueryFilter(parameter);
        Sort sort = getSort(parameter);
        TopDocs topFieldDocs = searcher.search(query,
            filter,N, sort);
        if(N<topFieldDocs.totalHits)
            topFieldDocs = searcher.search(query, filter,
topFieldDocs.totalHits, sort);

In this way, i can achieve my goal.

2009/4/4 王巍巍 <ww...@gmail.com>

> thanks a lot, i got it[?]
>
> 2009/4/4 Chris Hostetter <ho...@fucit.org>
>
>
>> : The problem comes as in this procedure i has to set the third parameter
>> n
>> : and as a result, when user click the last page link, exception will be
>> : thrown when the total number of search results excesses the *n* i
>> specified
>> : in the program. How can i overcome this problem?
>>
>> you're going to need to change "n" ... typically people just use something
>> like...
>>        int n = DOCS_PER_PAGE * page_num
>>
>> have you looked at the Lucene Demo code?  it has a more complex example of
>> doing a paginated search (grep for doPagingSearch) ...
>>
>>
>> http://svn.apache.org/viewvc/lucene/java/trunk/src/demo/org/apache/lucene/demo/SearchFiles.java?view=markup
>>
>>
>> : I've posted this problem twice and seen no reply. Could anyone offer a
>> : hand?  Thanks.
>>
>> You should consider posting to the java-user@lucene mailing list which
>> is specificly focused on discussions of using hte java API ...
>> general@lucene is a broader list for discussions about the braoder Lucene
>> project, or as a getting started point for people who aren't even sure
>> which Lucene technology (PyLucene, Lucene-Java, Solr, Mahout, Nutch,
>> etc...) might be useful for them.
>>
>>
>>
>>
>> -Hoss
>>
>>
>
>
> --
> 王巍巍(Weiwei Wang)
> Department of Computer Science
> Gulou Campus of Nanjing University
> Nanjing, P.R.China, 210093
>
> Mobile: 86-13913310569
> MSN: ww.wang.cs@gmail.com
> Homepage: http://cs.nju.edu.cn/rl/weiweiwang
>



-- 
王巍巍(Weiwei Wang)
Department of Computer Science
Gulou Campus of Nanjing University
Nanjing, P.R.China, 210093

Mobile: 86-13913310569
MSN: ww.wang.cs@gmail.com
Homepage: http://cs.nju.edu.cn/rl/weiweiwang

Re: hwo to get paged search result

Posted by 王巍巍 <ww...@gmail.com>.
thanks a lot, i got it[?]

2009/4/4 Chris Hostetter <ho...@fucit.org>

>
> : The problem comes as in this procedure i has to set the third parameter n
> : and as a result, when user click the last page link, exception will be
> : thrown when the total number of search results excesses the *n* i
> specified
> : in the program. How can i overcome this problem?
>
> you're going to need to change "n" ... typically people just use something
> like...
>        int n = DOCS_PER_PAGE * page_num
>
> have you looked at the Lucene Demo code?  it has a more complex example of
> doing a paginated search (grep for doPagingSearch) ...
>
>
> http://svn.apache.org/viewvc/lucene/java/trunk/src/demo/org/apache/lucene/demo/SearchFiles.java?view=markup
>
>
> : I've posted this problem twice and seen no reply. Could anyone offer a
> : hand?  Thanks.
>
> You should consider posting to the java-user@lucene mailing list which
> is specificly focused on discussions of using hte java API ...
> general@lucene is a broader list for discussions about the braoder Lucene
> project, or as a getting started point for people who aren't even sure
> which Lucene technology (PyLucene, Lucene-Java, Solr, Mahout, Nutch,
> etc...) might be useful for them.
>
>
>
>
> -Hoss
>
>


-- 
王巍巍(Weiwei Wang)
Department of Computer Science
Gulou Campus of Nanjing University
Nanjing, P.R.China, 210093

Mobile: 86-13913310569
MSN: ww.wang.cs@gmail.com
Homepage: http://cs.nju.edu.cn/rl/weiweiwang