-->
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.  [ 2 posts ] 
Author Message
 Post subject: Understanding Hibernate Search Filters
PostPosted: Tue Dec 16, 2008 1:21 am 
Newbie

Joined: Tue Dec 16, 2008 12:47 am
Posts: 1
I am trying to implement Hibernate search in my existing spring/hibernate application. In the earlier implementation, I had a SQL like this-

select field1, field2, field3, searchField
from table1
where
field1 = 100
and field2 = 200
and field3 = 300
and searchField like '%some text%'

field1+field2+field3 is the composite primary key here.

For hibernate search, I created an entity class EntityClass, mapped field1, 2 and 3 as @Id via another @Embeddable class which defines these fields as class properties. Also defined searchField as @Field with tokenized index in the entity class.

I had an existing database, so I had to do the initial index creation manually.

This is the code I am using to execute search query-

Code:
String fields[] = new String[]("field1', "field2", "field3","searchField");
MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, new StandardAnalyzer());
Query luceneQuery;
luceneQuery = parser.parse("some text");
org,hibernate.Query hibQuery = fullTextSession.createFullTextQuery(luceneQuery, EntityClass.class);
List result = hibQuery.list();


My question is-
compared to the original SQL query, I am passing the value of where clause searchField condition in the parser.parse(....) line. How do I pass the values of other where clause conditions (field1, 2, 3) in the lucene/hibernate search query?

I am new to hibernate search, so please pardon my ignorance if it looks too naive.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2008 12:51 pm 
Hibernate Team
Hibernate Team

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

instead of using a MultiFieldQueryParser you should programmatically create a Lucene BooleanQuery. You can create one clause for each field and combine them with 'AND'. Have a look at the Lucene Query API and the different ways to build a query.

--Hardy


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