You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Eric Jain <Er...@isb-sib.ch> on 2006/03/07 15:08:29 UTC

Re: Get only count

Anton Potehin wrote:
> Now I create new search for get number of results. For example:
> 
> IndexSearcher is = ...
> 
> Query q = ... 
> 
> numberOfResults = Is.search(q).length();
> 
> Can I accelerate this example ? And how ?

Perhaps something like:

class CountingHitCollector
   implements HitCollector
{
   public int count;

   public void collect(int doc, float score)
   {
     if (score > 0.0f)
       ++count;
   }
}

...

CountingHitCollector c = new CountingHitCollector();
searcher.search(query, c);
int hits = c.count;


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Get only count

Posted by Paul Elschot <pa...@xs4all.nl>.
On Wednesday 08 March 2006 09:25, anton@orbita1.ru wrote:
> Signifies this that method collect can be called for document with score <=
> 0 ?

The collect() method is called after next() on the top level Scorer has 
returned true. In between score() is called on that Scorer to provide the 
score value, but the score value is not tested.
Most Scorers give only positive score values for matching documents.

This is implemented in the IndexSearcher.search(...) and
Scorer.score(HitCollector) methods.

Regards,
Paul Elschot

> 
> -----Original Message-----
> From: Yonik Seeley [mailto:yseeley@gmail.com] 
> Sent: Tuesday, March 07, 2006 6:35 PM
> To: java-user@lucene.apache.org
> Subject: Re: Get only count
> Importance: High
> 
> On 3/7/06, anton@orbita1.ru <an...@orbita1.ru> wrote:
> > Can have matching document score equals zero ?
> 
> Yes.  Scorers don't generally use "score" to determine if a document
> matched the query.
> Scores <= 0.0f are currently screened out at the top level search
> functions, but not when you use a HitCollector yourself.
> 
> -Yonik
> 
> 
> > -----Original Message-----
> > From: Yonik Seeley [mailto:yseeley@gmail.com]
> > Sent: Tuesday, March 07, 2006 6:20 PM
> > To: java-user@lucene.apache.org
> > Subject: Re: Get only count
> > Importance: High
> >
> > On 3/7/06, anton@orbita1.ru <an...@orbita1.ru> wrote:
> > > While you added "if (score > 0.0f)". Javadoc contain lines
> > > "HitCollector.collect(int,float) is called for every non-zero scoring".
> >
> > That should probably read "is called for every matching document".
> >
> > -Yonik
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


RE: Get only count

Posted by an...@orbita1.ru.
Signifies this that method collect can be called for document with score <=
0 ?

-----Original Message-----
From: Yonik Seeley [mailto:yseeley@gmail.com] 
Sent: Tuesday, March 07, 2006 6:35 PM
To: java-user@lucene.apache.org
Subject: Re: Get only count
Importance: High

On 3/7/06, anton@orbita1.ru <an...@orbita1.ru> wrote:
> Can have matching document score equals zero ?

Yes.  Scorers don't generally use "score" to determine if a document
matched the query.
Scores <= 0.0f are currently screened out at the top level search
functions, but not when you use a HitCollector yourself.

-Yonik


> -----Original Message-----
> From: Yonik Seeley [mailto:yseeley@gmail.com]
> Sent: Tuesday, March 07, 2006 6:20 PM
> To: java-user@lucene.apache.org
> Subject: Re: Get only count
> Importance: High
>
> On 3/7/06, anton@orbita1.ru <an...@orbita1.ru> wrote:
> > While you added "if (score > 0.0f)". Javadoc contain lines
> > "HitCollector.collect(int,float) is called for every non-zero scoring".
>
> That should probably read "is called for every matching document".
>
> -Yonik

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Get only count

Posted by Yonik Seeley <ys...@gmail.com>.
On 3/7/06, anton@orbita1.ru <an...@orbita1.ru> wrote:
> Can have matching document score equals zero ?

Yes.  Scorers don't generally use "score" to determine if a document
matched the query.
Scores <= 0.0f are currently screened out at the top level search
functions, but not when you use a HitCollector yourself.

-Yonik


> -----Original Message-----
> From: Yonik Seeley [mailto:yseeley@gmail.com]
> Sent: Tuesday, March 07, 2006 6:20 PM
> To: java-user@lucene.apache.org
> Subject: Re: Get only count
> Importance: High
>
> On 3/7/06, anton@orbita1.ru <an...@orbita1.ru> wrote:
> > While you added "if (score > 0.0f)". Javadoc contain lines
> > "HitCollector.collect(int,float) is called for every non-zero scoring".
>
> That should probably read "is called for every matching document".
>
> -Yonik

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


RE: Get only count

Posted by an...@orbita1.ru.
Can have matching document score equals zero ? 
-----Original Message-----
From: Yonik Seeley [mailto:yseeley@gmail.com] 
Sent: Tuesday, March 07, 2006 6:20 PM
To: java-user@lucene.apache.org
Subject: Re: Get only count
Importance: High

On 3/7/06, anton@orbita1.ru <an...@orbita1.ru> wrote:
> While you added "if (score > 0.0f)". Javadoc contain lines
> "HitCollector.collect(int,float) is called for every non-zero scoring".

That should probably read "is called for every matching document".

-Yonik

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Get only count

Posted by Yonik Seeley <ys...@gmail.com>.
On 3/7/06, anton@orbita1.ru <an...@orbita1.ru> wrote:
> While you added "if (score > 0.0f)". Javadoc contain lines
> "HitCollector.collect(int,float) is called for every non-zero scoring".

That should probably read "is called for every matching document".

-Yonik

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


RE: Get only count

Posted by an...@orbita1.ru.
While you added "if (score > 0.0f)". Javadoc contain lines
"HitCollector.collect(int,float) is called for every non-zero scoring".

-----Original Message-----
From: Eric Jain [mailto:Eric.Jain@isb-sib.ch] 
Sent: Tuesday, March 07, 2006 5:08 PM
To: java-user@lucene.apache.org
Subject: Re: Get only count
Importance: High

Anton Potehin wrote:
> Now I create new search for get number of results. For example:
> 
> IndexSearcher is = ...
> 
> Query q = ... 
> 
> numberOfResults = Is.search(q).length();
> 
> Can I accelerate this example ? And how ?

Perhaps something like:

class CountingHitCollector
   implements HitCollector
{
   public int count;

   public void collect(int doc, float score)
   {
     if (score > 0.0f)
       ++count;
   }
}

...

CountingHitCollector c = new CountingHitCollector();
searcher.search(query, c);
int hits = c.count;


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org