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 Maria Mosolova <Ma...@corp.aol.com> on 2008/01/15 21:47:03 UTC
best way to get number of documents in a Solr index
Hello,
I am looking for the best way to get the number of documents in a Solr
index. I'd like to do it from a java code using solrj. Any suggestions
are welcome.
Thank you in advance,
Maria mosolova
Re: best way to get number of documents in a Solr index
Posted by Ryan McKinley <ry...@gmail.com>.
try a query with q=*:*
the 'numFound' will be every document -- use &rows=0 to avoid returing
docs (if you like)
ryan
Maria Mosolova wrote:
> Hello,
>
> I am looking for the best way to get the number of documents in a Solr
> index. I'd like to do it from a java code using solrj. Any suggestions
> are welcome.
>
> Thank you in advance,
> Maria mosolova
>
Re: best way to get number of documents in a Solr index
Posted by Maria Mosolova <Ma...@corp.aol.com>.
Thanks a lot Brian!
Maria
Brian Whitman wrote:
>
> On Jan 15, 2008, at 3:47 PM, Maria Mosolova wrote:
>
>> Hello,
>>
>> I am looking for the best way to get the number of documents in a
>> Solr index. I'd like to do it from a java code using solrj.
>
>
> public int resultCount() {
> try {
> SolrQuery q = new SolrQuery("*:*");
> QueryResponse rq = solr.query(q);
> return rq.getResults().getNumFound();
> } catch (org.apache.solr.client.solrj.SolrServerException e) {
> System.err.println("Query problem");
> } catch (java.io.IOException e) {
> System.err.println("Other error");
> }
> return -1;
> }
>
>
>
Re: best way to get number of documents in a Solr index
Posted by Brian Whitman <br...@variogr.am>.
On Jan 15, 2008, at 3:47 PM, Maria Mosolova wrote:
> Hello,
>
> I am looking for the best way to get the number of documents in a
> Solr index. I'd like to do it from a java code using solrj.
public int resultCount() {
try {
SolrQuery q = new SolrQuery("*:*");
QueryResponse rq = solr.query(q);
return rq.getResults().getNumFound();
} catch (org.apache.solr.client.solrj.SolrServerException e) {
System.err.println("Query problem");
} catch (java.io.IOException e) {
System.err.println("Other error");
}
return -1;
}