my worry is actually about the lucene's performance.

if lucene collects thousands of hits instead of actually n (<<< a couple of 
1000s) hits, then this creates performance issue.

ScoreDoc array is ok as i mentioned ie, it has size n.
i will check count api.

Best regards
________________________________
From: Adrien Grand <jpou...@gmail.com>
Sent: Tuesday, June 8, 2021 2:46 AM
To: Lucene Users Mailing List
Cc: Baris Kazar
Subject: Re: An interesting case

When you call IndexSearcher#search(Query query, int n), there are two cases:
 - either your query matches n hits or more, and the TopDocs object will have a 
ScoreDoc[] array that contains the n best scoring hits sorted by descending 
score,
 - or your query matches less then n hits and then the TopDocs object will have 
all matches in the ScoreDoc[] array, sorted by descending score.

In both cases, TopDocs#totalHits gives information about the total number of 
matches of the query. On older versions of Lucene (<7.0) this is an integer 
that is always accurate, while on more recent versions of Lucene (>= 8.0) it is 
a lower bound of the total number of matches. It typically returns the number 
of collected documents indeed, though this is an implementation detail that 
might change in the future.

If you want to count the number of matches of a Query precisely, you can use 
IndexSearcher#count.

On Tue, Jun 8, 2021 at 7:51 AM 
<baris.ka...@oracle.com<mailto:baris.ka...@oracle.com>> wrote:
https://stackoverflow.com/questions/50368313/relation-between-topdocs-totalhits-and-parameter-n-of-indexsearcher-search<https://urldefense.com/v3/__https://stackoverflow.com/questions/50368313/relation-between-topdocs-totalhits-and-parameter-n-of-indexsearcher-search__;!!GqivPVa7Brio!JjLGw8TaYQcqSC7BtpPSZl5dl-WqgwwcgGFhOqHSUKIsCaTSNpoDvOJjq0BbkQhfpw$>

looks like someone else also had this problem, too.

Any suggestions please?

Best regards


On 6/8/21 1:36 AM, baris.ka...@oracle.com<mailto:baris.ka...@oracle.com> wrote:
> Hi,-
>
>  I use IndexSearcher.search API with two parameters like Query and int
> number (i set as 20).
>
> However, when i look at the TopDocs object which is the result of this
> above API call
>
> i see thousands of hits from totalhits. Is this inaccurate or Lucene
> is doing actually search based on that many results?
>
> But when i iterate over result of above API call's scoreDocs object i
> get int number of hits (ie, 20 hits).
>
>
> I am trying to find out why org.apache.lucene.search.Topdocs.TotalHits
> report a number of collected results than
>
> the actual number of results. I see on the order of couple of
> thousands vs 20.
>
>
> Best regards
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: 
java-user-unsubscr...@lucene.apache.org<mailto:java-user-unsubscr...@lucene.apache.org>
For additional commands, e-mail: 
java-user-h...@lucene.apache.org<mailto:java-user-h...@lucene.apache.org>



--
Adrien

Reply via email to