-->
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.  [ 3 posts ] 
Author Message
 Post subject: Querying same field names but in different entities how?
PostPosted: Thu Jul 10, 2008 9:44 pm 
Regular
Regular

Joined: Fri Oct 05, 2007 3:22 am
Posts: 69
So doing a basic test I have this.

// Submission
BooleanQuery submissionBooleanQuery = new BooleanQuery();
QueryParser submissionParser = new QueryParser( "name", analyzer );
submissionParser.setAllowLeadingWildcard( true );
//Query submissionQuery = submissionParser.parse( this.searchSubmissionName );
Query submissionQuery = submissionParser.parse( "this should not be found" );
submissionBooleanQuery.add( submissionQuery, BooleanClause.Occur.MUST ) ;
submissionQuery.setBoost( 2f );

// Event
BooleanQuery eventBooleanQuery = new BooleanQuery();
QueryParser eventParser = new QueryParser( "name", analyzer );
eventParser.setAllowLeadingWildcard( true );
Query eventQuery = eventParser.parse( this.searchEventName );
eventBooleanQuery.add( eventQuery, BooleanClause.Occur.MUST );
eventBooleanQuery.setBoost( 2f );

// Join them
overallQuery.add( submissionBooleanQuery, BooleanClause.Occur.SHOULD );
overallQuery.add( eventBooleanQuery, BooleanClause.Occur.SHOULD );

return ( ( FullTextEntityManager ) em ).createFullTextQuery( overallQuery, A.class, B.class );

I want it so that the first submissionQueryis applied to A.class and the second eventBooleanQuery applied to B.class.

My result sets include instances of B which have terms found in the first query ""this should not be found". How do I limit these?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 11, 2008 6:46 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

You could change the field name under which the property 'name' gets indexed. For example, index A.name as nameA and B.name as nameB and change the queries accordingly.

If you don't want to change the field name you could index another unique field for each of the classes. Then add another TermQuery to both submissionQuery and eventBooleanQuery including this field using a BooleanClause.Occur.MUST. In fact, you could use _hibernate_class which already exists. Hibernate uses it to add the class name to the Lucene document. Have a look at the index (using Luke) to see how the documents look like.

However, I would recommend you to rely on intrinsic behaviour of Hibernate Search.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 11, 2008 12:38 pm 
Regular
Regular

Joined: Fri Oct 05, 2007 3:22 am
Posts: 69
Thanks for your response.

I was under the impression that the order the queries were placed would be matched up with the order of the classes that appear in the query list.

So for example:

overallQuery.add( submissionBooleanQuery, BooleanClause.Occur.SHOULD );
overallQuery.add( eventBooleanQuery, BooleanClause.Occur.SHOULD );

return ( ( FullTextEntityManager ) em ).createFullTextQuery( overallQuery, Submission.class, EventLang.class );

My expectation here is that the submissionBooleanQuery would only run against the Submission.class and the eventBooleanQuery would only run against the EventLang.class. Based on the behavior this doesn't appear to be the case.


hardy.ferentschik wrote:
Hi,

You could change the field name under which the property 'name' gets indexed. For example, index A.name as nameA and B.name as nameB and change the queries accordingly.

If you don't want to change the field name you could index another unique field for each of the classes. Then add another TermQuery to both submissionQuery and eventBooleanQuery including this field using a BooleanClause.Occur.MUST. In fact, you could use _hibernate_class which already exists. Hibernate uses it to add the class name to the Lucene document. Have a look at the index (using Luke) to see how the documents look like.

However, I would recommend you to rely on intrinsic behaviour of Hibernate Search.

--Hardy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.