[ 
https://issues.apache.org/jira/browse/LUCENE-942?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Shai Erera closed LUCENE-942.
-----------------------------

    Resolution: Not A Problem

TopDocsCollector documents that you cannot call topDocs() more than once for 
each search execution.

> TopDocCollector.topDocs throws ArrayIndexOutOfBoundsException when called 
> twice
> -------------------------------------------------------------------------------
>
>                 Key: LUCENE-942
>                 URL: https://issues.apache.org/jira/browse/LUCENE-942
>             Project: Lucene - Java
>          Issue Type: Bug
>          Components: Search
>    Affects Versions: 2.2
>            Reporter: Aaron Isotton
>            Priority: Minor
>
> Here's the implementation of TopDocCollector.topDocs():
>   public TopDocs topDocs() {
>     ScoreDoc[] scoreDocs = new ScoreDoc[hq.size()];
>     for (int i = hq.size()-1; i >= 0; i--)      // put docs in array
>       scoreDocs[i] = (ScoreDoc)hq.pop();
>       
>     float maxScore = (totalHits==0)
>       ? Float.NEGATIVE_INFINITY
>       : scoreDocs[0].score;
>     
>     return new TopDocs(totalHits, scoreDocs, maxScore);
>   }
> When you call topDocs(), hq gets emptied. Thus the second time you call it 
> scoreDocs.length will be 0 and scoreDocs[0] will throw an 
> ArrayIndexOutOfBoundsException.
> I don't know whether this 'call only once' semantics is intended behavior or 
> not; if not, it should be fixed, if yes it should be documented.
> Thanks a lot for an absolutely fantastic product,
> Aaron

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org

Reply via email to