-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 
Author Message
 Post subject: [Hibernate Search] Query and multiple result classes
PostPosted: Tue Jul 24, 2007 9:30 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
Hello,

I have a question about a query and multiple result classes.

For example, I have Class1 and Class2 with Class2 embedded in Class1.

Both classes have an "att" attribute.
I want to made a search like that :
Code:
class2.att:"value1" AND class2.att:"value2"


but I think I can't do that, so I must do

Code:
att:"value1" AND att:"value2"


And I want the result is Class1 and Class2.

Code:
fullTextQuery = fullTextSession.createFullTextQuery( luceneQuery, Class1.class, Class2.class );


The problem is that I think
Code:
att:"value1"
will search on Class1.att and Class2.att, not just Class1.att

Is there any madder to specify in which class HSearch must search (without changing attribute names) ?

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 25, 2007 3:10 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Do you mean?
Code:
class1.att:"value1" AND class2.att:"value2"


Then you can use the special DocumentBuilder.CLASS_FIELDNAME to constraint on the fully qualified class name. (I need to expose that properly at some point).

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 25, 2007 3:15 pm 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
Yes, it's what I mean :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 27, 2007 4:33 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
Hum, I tried to understand how to use DocumentBuilder.CLASS_FIELDNAME but I don't understand :S.

Could you explain me how to made queries with class constraint ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 27, 2007 12:52 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
"(" + DocumentBuilder.CLASS_FIELDNAME +":my.fq.ClassName AND attr1:constraint ) OR (" + DocumentBuilder.CLASS_FIELDNAME +":my.fq.ClassName2 AND attr1:constraint )"

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 27, 2007 1:08 pm 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
oh, thank you very much.

my.fq.ClassName is just the classname ? For example Class1 ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 30, 2007 8:44 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
In luke, _hibernate_class value is "com.demo.Entite".

I wrote that :
Code:
query = "_hibernate_class:com.demo.Entite";


But nothing was found. Then, I tried
Code:
query = "_hibernate_class:com.demo.Entite*";


And there are results. Is there spaces at the end of the classname ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 30, 2007 3:52 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
ah no but the queryParser tokenize all fields, so you might want to build the query programatically.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 30, 2007 4:10 pm 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
Hum, I don't understand.

I must use
Code:
query = "_hibernate_class:\"com.demo.Entite\"";

to have the full string ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 30, 2007 4:37 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
no you need to use a TermQuery

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 31, 2007 2:51 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
I don't understand ^^

Currently, I use
Code:
org.apache.lucene.search.Query luceneQuery = parser.parse(stringQuery);


so you say that I muse use
extended by org.apache.lucene.search.TermQuery luceneQuery = parser.parse(stringQuery);
:S ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 31, 2007 8:15 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
emmanuel wrote:
"(" + DocumentBuilder.CLASS_FIELDNAME +":my.fq.ClassName AND attr1:constraint ) OR (" + DocumentBuilder.CLASS_FIELDNAME +":my.fq.ClassName2 AND attr1:constraint )"


I think this is equivalent to
Code:
class1.att:"value1" OR class2.att:"value2"


not

Code:
class1.att:"value1" AND class2.att:"value2"


I will rename my fields to have unique name, it's too complicated :S


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.