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 Ravi <ra...@siti.com> on 2006/01/18 14:20:09 UTC

:intersection of two hits objects:

Hi 

 

 

I want to find out the intersection of two hits objects  please help me

 

 

Hits hits1 = Searcher.searh(strQuery1); 

Hits hits2 = Searcher.searh(strQuery2);

 

 

Now In hits1 contains records numbers 3,4 ,5,6 and 

       Hits2 contains records numbers 3,6,8,9

Now I need a solution which can give the hits object which contains  3,6
records

 

 

 

I would appreciate any help from all 

 

 

Thanks

 

Ravi Kumar Jaladanki

 

 

 

 


RE: :intersection of two hits objects:

Posted by Ravi <ra...@siti.com>.
Thanks for your valuable suggestions to me.. I am very much glad to you for
this response. Now I understood where I am going wrong so I will try use the
first solution given by you 

Thanks 
Ravi Kumar Jaladanki


-----Original Message-----
From: hossman@hal.rescomp.berkeley.edu
[mailto:hossman@hal.rescomp.berkeley.edu] On Behalf Of Chris Hostetter
Sent: Thursday, January 19, 2006 12:51 PM
To: java-user@lucene.apache.org
Subject: RE: :intersection of two hits objects:


The first thing you need to keep in mind, is that a Hits object doesn't
"contain" results.  The Hits class is provided as a convincent way to
access results in order, that provides some prefecthing of ids/scores, and
caching of doc stored fields.

Iterating over an entire Hits object is *never* a good idea.
Depending on how big your result set is, iterating over every doc in the
results with a Hits object will re-execute your search over and over again
as you reach the end of it's buffer.

If it's not entirely obvious yet: there is no way to make a Hits object
and "add" or "remove" documents to/from it.   all a Hits objects has in it
is your orriginal Query, a refrnece to your searcher, and a cache.


if you need a Hits obejct ot contain only the results that can be found in
both of two queries A and B, then you should do one of two things:

  1) combine A and B in a boolean query ... this is the "right" option if
you want the scores in your results to be based on the aggregate scores
from A and B.

  2) execute A filtered by B (or B filtered by A) ... this is the "right"
option if you want the scores in your results to be based on just one
query ... and the other should only be used to restrict the results.


if you don't have the orriginal queries A and B, and all you have is the
Hits that resulted from those queries ... then i suggest you change your
app.



: Date: Thu, 19 Jan 2006 11:42:41 +0530
: From: Ravi <ra...@siti.com>
: Reply-To: java-user@lucene.apache.org
: To: java-user@lucene.apache.org
: Subject: RE: :intersection of two hits objects:
:
: Thanks for your help ,
:
: I am able to get the record numbers in BitSet object but how to iterate in
: the first hits1 object with the bitset object and retain only those
: documents  which contains ids existed in bitset object..
:
:
: Thanks
: Ravi Kumar jaladanki
:
: -----Original Message-----
: From: Dave Kor [mailto:davekor@gmail.com]
: Sent: Thursday, January 19, 2006 7:01 AM
: To: java-user@lucene.apache.org
: Subject: Re: :intersection of two hits objects:
:
: On 1/18/06, Ravi <ra...@siti.com> wrote:
: > Hi
: >
: > I want to find out the intersection of two hits objects  please help me
: >
: > Hits hits1 = Searcher.searh(strQuery1);
: > Hits hits2 = Searcher.searh(strQuery2);
: >
: > Now In hits1 contains records numbers 3,4 ,5,6 and
: >        Hits2 contains records numbers 3,6,8,9
: >
: > Now I need a solution which can give the hits object which contains  3,6
: > records
: >
:
: You can iterate through the Hits objects, flagging the document
: numbers in a java.util.BitSet. To compare hits between different
: queries, all you have to do is bitset1.and(bitset2).
:
: --
: Dave Kor, Research Assistant
: Center for Information Mining and Extraction
: School of Computing
: National University of Singapore.
:
: ---------------------------------------------------------------------
: 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
:



-Hoss


---------------------------------------------------------------------
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: :intersection of two hits objects:

Posted by Chris Hostetter <ho...@fucit.org>.
The first thing you need to keep in mind, is that a Hits object doesn't
"contain" results.  The Hits class is provided as a convincent way to
access results in order, that provides some prefecthing of ids/scores, and
caching of doc stored fields.

Iterating over an entire Hits object is *never* a good idea.
Depending on how big your result set is, iterating over every doc in the
results with a Hits object will re-execute your search over and over again
as you reach the end of it's buffer.

If it's not entirely obvious yet: there is no way to make a Hits object
and "add" or "remove" documents to/from it.   all a Hits objects has in it
is your orriginal Query, a refrnece to your searcher, and a cache.


if you need a Hits obejct ot contain only the results that can be found in
both of two queries A and B, then you should do one of two things:

  1) combine A and B in a boolean query ... this is the "right" option if
you want the scores in your results to be based on the aggregate scores
from A and B.

  2) execute A filtered by B (or B filtered by A) ... this is the "right"
option if you want the scores in your results to be based on just one
query ... and the other should only be used to restrict the results.


if you don't have the orriginal queries A and B, and all you have is the
Hits that resulted from those queries ... then i suggest you change your
app.



: Date: Thu, 19 Jan 2006 11:42:41 +0530
: From: Ravi <ra...@siti.com>
: Reply-To: java-user@lucene.apache.org
: To: java-user@lucene.apache.org
: Subject: RE: :intersection of two hits objects:
:
: Thanks for your help ,
:
: I am able to get the record numbers in BitSet object but how to iterate in
: the first hits1 object with the bitset object and retain only those
: documents  which contains ids existed in bitset object..
:
:
: Thanks
: Ravi Kumar jaladanki
:
: -----Original Message-----
: From: Dave Kor [mailto:davekor@gmail.com]
: Sent: Thursday, January 19, 2006 7:01 AM
: To: java-user@lucene.apache.org
: Subject: Re: :intersection of two hits objects:
:
: On 1/18/06, Ravi <ra...@siti.com> wrote:
: > Hi
: >
: > I want to find out the intersection of two hits objects  please help me
: >
: > Hits hits1 = Searcher.searh(strQuery1);
: > Hits hits2 = Searcher.searh(strQuery2);
: >
: > Now In hits1 contains records numbers 3,4 ,5,6 and
: >        Hits2 contains records numbers 3,6,8,9
: >
: > Now I need a solution which can give the hits object which contains  3,6
: > records
: >
:
: You can iterate through the Hits objects, flagging the document
: numbers in a java.util.BitSet. To compare hits between different
: queries, all you have to do is bitset1.and(bitset2).
:
: --
: Dave Kor, Research Assistant
: Center for Information Mining and Extraction
: School of Computing
: National University of Singapore.
:
: ---------------------------------------------------------------------
: 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
:



-Hoss


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


Re: :intersection of two hits objects:

Posted by Daniel Noll <da...@nuix.com.au>.
Ravi wrote:
> Thanks for your help ,
>
> I am able to get the record numbers in BitSet object but how to iterate in
> the first hits1 object with the bitset object and retain only those
> documents  which contains ids existed in bitset object..
>   
Ah.

I take it that you want the results as another Hits object.

Is there any reason you can't just reexecute the whole thing using a 
BooleanQuery to AND the two queries together?  That would give you more 
or less what you want.

Daniel

-- 
Daniel Noll

Nuix Australia Pty Ltd
Suite 79, 89 Jones St, Ultimo NSW 2007, Australia
Phone: (02) 9280 0699
Fax:   (02) 9212 6902

This message is intended only for the named recipient. If you are not
the intended recipient you are notified that disclosing, copying,
distributing or taking any action in reliance on the contents of this
message or attachment is strictly prohibited.


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


RE: :intersection of two hits objects:

Posted by Ravi <ra...@siti.com>.
Thanks for your help ,

I am able to get the record numbers in BitSet object but how to iterate in
the first hits1 object with the bitset object and retain only those
documents  which contains ids existed in bitset object..


Thanks
Ravi Kumar jaladanki

-----Original Message-----
From: Dave Kor [mailto:davekor@gmail.com] 
Sent: Thursday, January 19, 2006 7:01 AM
To: java-user@lucene.apache.org
Subject: Re: :intersection of two hits objects:

On 1/18/06, Ravi <ra...@siti.com> wrote:
> Hi
>
> I want to find out the intersection of two hits objects  please help me
>
> Hits hits1 = Searcher.searh(strQuery1);
> Hits hits2 = Searcher.searh(strQuery2);
>
> Now In hits1 contains records numbers 3,4 ,5,6 and
>        Hits2 contains records numbers 3,6,8,9
>
> Now I need a solution which can give the hits object which contains  3,6
> records
>

You can iterate through the Hits objects, flagging the document
numbers in a java.util.BitSet. To compare hits between different
queries, all you have to do is bitset1.and(bitset2).

--
Dave Kor, Research Assistant
Center for Information Mining and Extraction
School of Computing
National University of Singapore.

---------------------------------------------------------------------
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: :intersection of two hits objects:

Posted by Dave Kor <da...@gmail.com>.
On 1/18/06, Ravi <ra...@siti.com> wrote:
> Hi
>
> I want to find out the intersection of two hits objects  please help me
>
> Hits hits1 = Searcher.searh(strQuery1);
> Hits hits2 = Searcher.searh(strQuery2);
>
> Now In hits1 contains records numbers 3,4 ,5,6 and
>        Hits2 contains records numbers 3,6,8,9
>
> Now I need a solution which can give the hits object which contains  3,6
> records
>

You can iterate through the Hits objects, flagging the document
numbers in a java.util.BitSet. To compare hits between different
queries, all you have to do is bitset1.and(bitset2).

--
Dave Kor, Research Assistant
Center for Information Mining and Extraction
School of Computing
National University of Singapore.

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


Re: :intersection of two hits objects:

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jan 19, 2006, at 2:57 AM, Ravi wrote:
> Can  u please tell me how to use this query in loop because he can  
> refine
> the search n number of time so how to maintain all the queries in
> QueryFilter and use of them ,,,,, Please help me I need very urgent.

If you're continually refining queries, I encourage you to consider  
AND'ing successive clauses in a BooleanQuery.  Using a Filter  
requires running one query to generate a BitSet and then another  
query using the BitSet as a constraint, so you'd likely find better  
performance by ANDing.

	Erik


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


RE: :intersection of two hits objects:

Posted by Ravi <ra...@siti.com>.
Hi Erik

Can  u please tell me how to use this query in loop because he can refine
the search n number of time so how to maintain all the queries in
QueryFilter and use of them ,,,,, Please help me I need very urgent.


Thanks
Ravi Kumar Jaladanki

-----Original Message-----
From: Erik Hatcher [mailto:erik@ehatchersolutions.com] 
Sent: Wednesday, January 18, 2006 7:12 PM
To: java-user@lucene.apache.org
Subject: Re: :intersection of two hits objects:


On Jan 18, 2006, at 8:20 AM, Ravi wrote:
>
> I want to find out the intersection of two hits objects  please  
> help me
>
>
>
>
>
> Hits hits1 = Searcher.searh(strQuery1);
>
> Hits hits2 = Searcher.searh(strQuery2);
>
>
>
>
>
> Now In hits1 contains records numbers 3,4 ,5,6 and
>
>        Hits2 contains records numbers 3,6,8,9
>
> Now I need a solution which can give the hits object which  
> contains  3,6
> records

One option is to construct a QueryFilter with the first query, and  
use the search(Query, Filter) method.  Another option is to AND the  
two queries together by wrapping them in a BooleanQuery with both  
clauses required.

	Erik



---------------------------------------------------------------------
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: :intersection of two hits objects:

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jan 18, 2006, at 8:20 AM, Ravi wrote:
>
> I want to find out the intersection of two hits objects  please  
> help me
>
>
>
>
>
> Hits hits1 = Searcher.searh(strQuery1);
>
> Hits hits2 = Searcher.searh(strQuery2);
>
>
>
>
>
> Now In hits1 contains records numbers 3,4 ,5,6 and
>
>        Hits2 contains records numbers 3,6,8,9
>
> Now I need a solution which can give the hits object which  
> contains  3,6
> records

One option is to construct a QueryFilter with the first query, and  
use the search(Query, Filter) method.  Another option is to AND the  
two queries together by wrapping them in a BooleanQuery with both  
clauses required.

	Erik



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