lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Senthil <senthilru...@gmail.com>
Subject Re: Getting
Date Fri, 24 Dec 2010 06:59:57 GMT
Hi

 As long as your code request for 100 results, it definitely return of max
of 100 documents only.
   See your code:
    TopDocs hits=searcher.search(query, null, *100*);

Regards
Senthil

On Fri, Dec 24, 2010 at 6:10 PM, Jawahar Lal <jlal@chambal.com> wrote:

> Hi,
>
>  I search for an query. Total searched records are 5000. I only shows 100
> records on one page. So I passed 100 as nDocs.
>
> I write the code in this way.
>
>           IndexSearcher searcher = new IndexSearcher(FSDirectory.open(new
> File(path)));
>
>            Query query = new QueryParser(Version.LUCENE_30, "field1", new
> StandardAnalyzer(Version.LUCENE_30)).parse("query");
>            Query query1 = new QueryParser(Version.LUCENE_30, "field2", new
> StandardAnalyzer(Version.LUCENE_30)).parse("query2");
>            BooleanQuery lucBoolQueryOTHER = new BooleanQuery();
>            lucBoolQueryOTHER.add(query, Occur.MUST);
>            lucBoolQueryOTHER.add(query1, Occur.MUST);
>
>            TopDocs hits=searcher.search(query, null, 100);
>
>            System.err.println("Total searched " + hits.totalHits);   >>
> 5000
>            System.err.println("Total docs " + hits.scoreDocs.length);  >>
> 100
>
> // The code to print 100 records on first page
>            for(int i=0;i<hits.scoreDocs.length;i++){
>
>
> System.out.println(searcher.doc(hits.scoreDocs[i].doc).getField("filename"));
>            }
>
> it worked fine.
>
> // Now I want to show all next search documents on Second Pages...when I
> tried in this way, I got the error.
>            for(int i=100;i<hits.totalHits;i++){
>
>
> System.out.println(searcher.doc(hits.scoreDocs[i].doc).getField("filename"));
>            }
>
>            searcher.close();
>
> java.lang.ArrayIndexOutOfBoundsException: 100
>        at Test.searchIndex(Test.java:96)
>        at Test.main(Test.java:54)
>
> Would need to perform searching again with different parameters to fetch
> next bunch of records ?
>
>
>
>
> Thanks
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message