You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Robert Brown <ro...@intelcompute.com> on 2011/10/28 11:16:34 UTC

Always return total number of documents

Currently I'm making 2 calls to Solr to be able to state "matched 20 
out of 200 documents".

Is there no way to return the total number of docs as part of a 
search?


--

IntelCompute
Web Design & Local Online Marketing

http://www.intelcompute.com


Re: Always return total number of documents

Posted by Erik Hatcher <er...@gmail.com>.
there is actually an interesting trick here using facet.query (which would only entail a single filter cache entry):

http://127.0.0.1:8888/solr/collection1/select?q={!tag=main}country:Spain&facet=on&facet.query={!ex=main key=total}*:*

[my test data has a country field]

Using facet tagging/exclusion you can get the total amount.  Note that you'll have to tag fq params and ex(clude) those as well on the facet.query ex sub-parameter, like this sort of thing:

  http://127.0.0.1:8888/solr/collection1/select?q={!tag=main}country:US&facet=on&facet.query={!ex=main,fq1 key=total}*:*&fq={!tag=fq1}last_name:Smith

With these you'll get a facet_querys/total section in the response with the total number of documents regardless of q/fq constraints.  

	Erik


On Oct 31, 2011, at 07:32 , Erick Erickson wrote:

> Why not have your app query admin/stats and cache the numDocs variable
> and just add it to each page you display? That way you'd only
> have to call the stats component once.
> 
> Well, actually, you'd have to periodically call it to catch index updates,
> but you'd cut down the number of queries.
> 
> Although an even simpler way would be to query for *:* and cache
> the number of results in your app for future reference.
> 
> Best
> Erick
> 
> On Fri, Oct 28, 2011 at 5:48 AM, Robert Brown <ro...@intelcompute.com> wrote:
>> Cheers Kuli,
>> 
>> This is actually of huge importance to our customers, to see how many
>> documents we store.
>> 
>> The faceting option sounds a bit messy, maybe we'll have to stick with
>> 2 queries.
>> 
>> 
>> ---
>> 
>> IntelCompute
>> Web Design & Local Online Marketing
>> 
>> http://www.intelcompute.com
>> 
>> On Fri, 28 Oct 2011 11:43:11 +0200, Michael Kuhlmann <ku...@solarier.de>
>> wrote:
>>> Am 28.10.2011 11:16, schrieb Robert Brown:
>>>> Is there no way to return the total number of docs as part of a search?
>>> 
>>> No, it isn't. Usually this information is of absolutely no value to the
>>> end user.
>>> 
>>> A workaround would be to add some field to the schema that has the same
>>> value for every document, and use this for facetting.
>>> 
>>> Greetings,
>>> Kuli
>> 
>> 


Re: Always return total number of documents

Posted by Erick Erickson <er...@gmail.com>.
Why not have your app query admin/stats and cache the numDocs variable
and just add it to each page you display? That way you'd only
have to call the stats component once.

Well, actually, you'd have to periodically call it to catch index updates,
but you'd cut down the number of queries.

Although an even simpler way would be to query for *:* and cache
the number of results in your app for future reference.

Best
Erick

On Fri, Oct 28, 2011 at 5:48 AM, Robert Brown <ro...@intelcompute.com> wrote:
> Cheers Kuli,
>
> This is actually of huge importance to our customers, to see how many
> documents we store.
>
> The faceting option sounds a bit messy, maybe we'll have to stick with
> 2 queries.
>
>
> ---
>
> IntelCompute
> Web Design & Local Online Marketing
>
> http://www.intelcompute.com
>
> On Fri, 28 Oct 2011 11:43:11 +0200, Michael Kuhlmann <ku...@solarier.de>
> wrote:
>> Am 28.10.2011 11:16, schrieb Robert Brown:
>>> Is there no way to return the total number of docs as part of a search?
>>
>> No, it isn't. Usually this information is of absolutely no value to the
>> end user.
>>
>> A workaround would be to add some field to the schema that has the same
>> value for every document, and use this for facetting.
>>
>> Greetings,
>> Kuli
>
>

Re: Always return total number of documents

Posted by Robert Brown <ro...@intelcompute.com>.
Cheers Kuli,

This is actually of huge importance to our customers, to see how many
documents we store.

The faceting option sounds a bit messy, maybe we'll have to stick with
2 queries.


---

IntelCompute
Web Design & Local Online Marketing

http://www.intelcompute.com

On Fri, 28 Oct 2011 11:43:11 +0200, Michael Kuhlmann <ku...@solarier.de>
wrote:
> Am 28.10.2011 11:16, schrieb Robert Brown:
>> Is there no way to return the total number of docs as part of a search?
> 
> No, it isn't. Usually this information is of absolutely no value to the
> end user.
> 
> A workaround would be to add some field to the schema that has the same
> value for every document, and use this for facetting.
> 
> Greetings,
> Kuli


Re: Always return total number of documents

Posted by Michael Kuhlmann <ku...@solarier.de>.
Am 28.10.2011 11:16, schrieb Robert Brown:
> Is there no way to return the total number of docs as part of a search?

No, it isn't. Usually this information is of absolutely no value to the
end user.

A workaround would be to add some field to the schema that has the same
value for every document, and use this for facetting.

Greetings,
Kuli