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 Clay Zhong <zj...@gmail.com> on 2008/11/04 13:31:53 UTC

Can lucene search from multi-index directory like using FK in database?

Hi Guys,

I meet some problems when using Lucene 2.3.2. After a lot of research, I
still can't find any ways to solve them. Hope you can give me some
advice..

1. Can I search different document from multi-index when they have
connections like FK in database?
For example,
Index Dir 1 (User): Field id, Field departmentId
Index Dir 2 (Department): Field id, Field location
How can I get all user that location is USA?
Well, I can index location into User, or search from Department first to
get departmentId. But they're really terrible, is there a better way?

2. How can I search from multi-index with one query? It's different from
using MultiSearcher.
For example, there's two fields, 'title' and 'content', when I search
'Java and Lucene', how can I get documents which contains 'Java' in
'title' and 'lucene' in 'content'? (not only 'Java and Lucene' in one
field). I can add a field contains both 'title' and 'content', but
that's really really bad solution....

That's all my questions, thanks for your patient.

Best Wishes
Clay Zhong


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


Re: Can lucene search from multi-index directory like using FK in database?

Posted by Chris Lu <ch...@gmail.com>.
These are common problems. In general, mapping database tables into 
Lucene Documents is not always good for performance. You may need to 
flatten objects to fit Lucene's shoes.

My answers are here respectively.

1. You have two alternatives here:
    1) create an index to contain both User and Field Location 
information. This is more efficient, but you will need to create a new 
index structure. But Lucene is just an "index", do not use it to mimic 
database structure.
    2) use your "terrible way" to retrieve department_id first, then to 
get the user_ids. This approach may not be that bad, although less 
performant.

2. You will need to create a little query parser to distribute words 
into two fields.

-- 
Chris Lu
-------------------------
Instant Scalable Full-Text Search On Any Database/Application
site: http://www.dbsight.net
demo: http://search.dbsight.com
Lucene Database Search in 3 minutes: 
http://wiki.dbsight.com/index.php?title=Create_Lucene_Database_Search_in_3_minutes
DBSight customer, a shopping comparison site, (anonymous per request) 
got 2.6 Million Euro funding!


Clay Zhong wrote:
> Hi Guys,
>
> I meet some problems when using Lucene 2.3.2. After a lot of research, I
> still can't find any ways to solve them. Hope you can give me some
> advice..
>
> 1. Can I search different document from multi-index when they have
> connections like FK in database?
> For example,
> Index Dir 1 (User): Field id, Field departmentId
> Index Dir 2 (Department): Field id, Field location
> How can I get all user that location is USA?
> Well, I can index location into User, or search from Department first to
> get departmentId. But they're really terrible, is there a better way?
>
> 2. How can I search from multi-index with one query? It's different from
> using MultiSearcher.
> For example, there's two fields, 'title' and 'content', when I search
> 'Java and Lucene', how can I get documents which contains 'Java' in
> 'title' and 'lucene' in 'content'? (not only 'Java and Lucene' in one
> field). I can add a field contains both 'title' and 'content', but
> that's really really bad solution....
>
> That's all my questions, thanks for your patient.
>
> Best Wishes
> Clay Zhong
>
>
> ---------------------------------------------------------------------
> 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 : Can lucene search from multi-index directory like using FK in database?

Posted by Ulrich Vachon <ul...@vidal.fr>.
Hello,

Erik has right, Lucene is not a RDBMS. If you want mix both world, you can use tools dedicated like Hibernate Search or Compass.

Ulrich VACHON

-------- Message d'origine--------
De: Clay Zhong [mailto:zjclay@gmail.com]
Date: mar. 04/11/2008 13:31
�: java-user@lucene.apache.org
Objet : Can lucene search from multi-index directory like using FK in database?
 
Hi Guys,

I meet some problems when using Lucene 2.3.2. After a lot of research, I
still can't find any ways to solve them. Hope you can give me some
advice..

1. Can I search different document from multi-index when they have
connections like FK in database?
For example,
Index Dir 1 (User): Field id, Field departmentId
Index Dir 2 (Department): Field id, Field location
How can I get all user that location is USA?
Well, I can index location into User, or search from Department first to
get departmentId. But they're really terrible, is there a better way?

2. How can I search from multi-index with one query? It's different from
using MultiSearcher.
For example, there's two fields, 'title' and 'content', when I search
'Java and Lucene', how can I get documents which contains 'Java' in
'title' and 'lucene' in 'content'? (not only 'Java and Lucene' in one
field). I can add a field contains both 'title' and 'content', but
that's really really bad solution....

That's all my questions, thanks for your patient.

Best Wishes
Clay Zhong


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


______________________________________________________________________
Cet e-mail a �t� scann� par MessageLabs Email Security System.
Pour plus d'informations, visitez http://www.messagelabs.com/email
______________________________________________________________________



Re: Can lucene search from multi-index directory like using FK in database?

Posted by Erick Erickson <er...@gmail.com>.
See below

On Tue, Nov 4, 2008 at 7:31 AM, Clay Zhong <zj...@gmail.com> wrote:

> Hi Guys,
>
> I meet some problems when using Lucene 2.3.2. After a lot of research, I
> still can't find any ways to solve them. Hope you can give me some
> advice..
>
> 1. Can I search different document from multi-index when they have
> connections like FK in database?
> For example,
> Index Dir 1 (User): Field id, Field departmentId
> Index Dir 2 (Department): Field id, Field location
> How can I get all user that location is USA?
> Well, I can index location into User, or search from Department first to
> get departmentId. But they're really terrible, is there a better way?
>

Whenever you start thinking this way, step back, take a deep
breath and remember that Lucene is a *text search* engine, not a
database engine. Forget all you know about data normalization
and construct your index so you do NOT have any conception of
foreign keys. De-normalize your data so you can do this
kind of thing with simple queries. Yes, this takes more room and
it may not be reasonable. But unless and until you *know* you'll
have space/performance problems, this should be your first
approach.

If that doesn't work, think about hybrid solutions where you put your
text in a Lucene index and the data you really, really do need to
use in a RDBMS way in a real-live database. If you search the
archives you'll see this discussed in some detail.


>
> 2. How can I search from multi-index with one query? It's different from
> using MultiSearcher.
> For example, there's two fields, 'title' and 'content', when I search
> 'Java and Lucene', how can I get documents which contains 'Java' in
> 'title' and 'lucene' in 'content'? (not only 'Java and Lucene' in one
> field). I can add a field contains both 'title' and 'content', but
> that's really really bad solution....
>

+title:java +content:lucene

should do the trick, but you'll have to write your own code to know
that the phrase "java and lucene" should be broken up this way.

Best
Erick


>
> That's all my questions, thanks for your patient.
>
> Best Wishes
> Clay Zhong
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>