lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erick Erickson" <>
Subject Re: How can I limit the number of hits in my query?
Date Mon, 14 May 2007 13:24:12 GMT
See below

On 5/14/07, David Leangen <> wrote:
> Hello!
> I am new to Lucene, so forgive me if my question is basic. I did try
> googling for an answer...
> For an ajax autocomplete widget, I am querying using Lucene. I only want
> to return, for example, the first 20 hits of anything that Lucene finds
> in whatever order Lucene gives to me.
> Two questions:
> - How can I limit the number of hits? I don't know in
>    advance what the data will be, so it's not feasible for
>    me to use RangeQuery.

You can use a TopDocs or a HitCollector object which allows you
to process each object as it's hit. But I doubt you need to do this. Under
the covers, a Hits object actually stops at about 100 documents and
re-executes the query to fetch the next 100 etc. So, I really doubt you'll
have any noticeable difference in either performance or resource
usage by getting fancy.

One of the design goals of the Hits object was exactly to incur the least
expense while getting the top 100 docs....

- Will this solve the problem I am getting with maxClauseCount?
>    maxClauseCount is set to 1024

No.  I expect you're using a wildcard, and wildcard handling is
complicated. Search the mail archive at
for TooManyClauses and you'll find a wealth of information about
why/how this happens and what to do to avoid it. Also, see

where this is one of th questions....


Thank you!
> David
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

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