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 Tom Hill <lu...@zvents.com> on 2006/03/23 20:51:30 UTC

Joins between index and database

Hi -

I have an application where I'm using Lucene to index the contents of 
a database. That's working fine.

But I have a problem where I'd like to retrieve a subset of the 
documents that match a search, based on a join table in the database.

How do people typically handle combining the results of a Lucene 
based search with the results of a database search?

Thanks,

Tom


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


Re: Joins between index and database

Posted by markharw00d <ma...@yahoo.co.uk>.
>See RangeFilter.bits() for some example code that creates a filter
>from terms. 
>

Also see TermsFilter in the "queries" module in the contrib section.



		
___________________________________________________________ 
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com

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


Re: Joins between index and database

Posted by Paul Elschot <pa...@xs4all.nl>.
On Thursday 23 March 2006 20:51, Tom Hill wrote:
> Hi -
> 
> I have an application where I'm using Lucene to index the contents of 
> a database. That's working fine.
> 
> But I have a problem where I'd like to retrieve a subset of the 
> documents that match a search, based on a join table in the database.
> 
> How do people typically handle combining the results of a Lucene 
> based search with the results of a database search?

One way is to get the values of some key field from the database,
create a Filter using terms created from these values, and use that
Filter in a search, or in a FilteredQuery.
See RangeFilter.bits() for some example code that creates a filter
from terms. Sorting the key values beforehand helps performance
for creating the filter. CachingWrapperFilter can also be handy.

In case you need a lot of filters for relatively few documents, have
a look here:
http://issues.apache.org/jira/browse/LUCENE-328

Regards,
Paul Elschot

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


Re: Joins between index and database

Posted by Pa...@saaconsultants.com.




You can get the results from the database and then create either some
boolean clauses to append to your existing Lucene query if the number of
results from the data base is small. If the number of results from the
database is large then you can create a filter. (Assuming you have some
common key field in your database and Lucene index). The downside to this
approach is you have to pull the results out of the database and create a
query/filter which can be timeconsuming if there are lots of results.

Depending upon your data you can sometimes avoid the database lookup by
indexing additional information in Lucene.  Bear in mind that Lucene can
index multiple values in a single field.

Regards

Paul I.




                                                                           
             Tom Hill                                                      
             <lucene-list@zven                                             
             ts.com>                                                    To 
                                       java-user@lucene.apache.org         
             23/03/2006 19:51                                           cc 
                                                                           
                                                                   Subject 
             Please respond to         Joins between index and database    
             java-user@lucene.                                             
                apache.org                                                 
                                                                           
                                                                           
                                                                           
                                                                           




Hi -

I have an application where I'm using Lucene to index the contents of
a database. That's working fine.

But I have a problem where I'd like to retrieve a subset of the
documents that match a search, based on a join table in the database.

How do people typically handle combining the results of a Lucene
based search with the results of a database search?

Thanks,

Tom


---------------------------------------------------------------------
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