-->
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.  [ 6 posts ] 
Author Message
 Post subject: Hibernate search for multiple words
PostPosted: Mon Jun 22, 2009 5:19 am 
Newbie

Joined: Mon Feb 16, 2009 2:59 am
Posts: 3
Location: Bangalore
I'm a newbie to hibernate search. I'm working on free text search where im indexing a filed to get skills in the following manner java,vb,j2ee. I'm able to retrieve the data from the db for all the scenarios of search except for single word search. Eg say i'm searching for java skills, i get all the results but fail to retrieve the data if it is something like j2ee,vb,java.
Here is the code,
List OpportunityList = new ArrayList();
SessionFactory sessionFactory = getHibernateTemplate().getSessionFactory();
Session session = sessionFactory.openSession();
FullTextSession fullTextSession = Search.getFullTextSession(session);
Transaction tx1 = fullTextSession.beginTransaction();
List<Opportunity> books = session.createQuery("from Opportunity").list();
//OpportunityList = books;
for (Opportunity opportunity1 : books) {
fullTextSession.index(opportunity1);
}
MultiFieldQueryParser parser = new MultiFieldQueryParser(new String[]{"title", "skillsNeeded", "str_location"},
new StandardAnalyzer());
org.apache.lucene.search.Query q = null;
f (position.equals("") && location.equals("") && !skills.equals("")) {
LOGGER.info("skill value:" + skills);
List result = new ArrayList();
try {
OpportunityList = books;
Iterator it = OpportunityList.iterator();

if (skills.contains(",")) {
String[] strskills = skills.split(",");

LOGGER.info("inside if condition");

for (int i = 0; i < strskills.length; i++) {
String skill = strskills[i] + "*";
q = parser.parse("skillsNeeded:" + skill);
LOGGER.info("query for skill " + q.toString());
org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(q, Opportunity.class);
result.addAll(hibQuery.list());
q = parser.parse("skillsNeeded:" + skills);

}
} else {
String strSkill = skills + "*";
q = parser.parse("skillsNeeded:" + strSkill);
LOGGER.info("query for skill " + q.toString());
org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(q, Opportunity.class);
result.addAll(hibQuery.list());
}

} catch (ParseException e) {
e.printStackTrace();
}
OpportunityList = result;
}
tx1.commit();
session.close();
return OpportunityList;
}

Any help in this direction would be of great help.
Thanks in advance

_________________
Shwetha Sharma


Top
 Profile  
 
 Post subject: Re: Hibernate search for multiple words
PostPosted: Tue Jun 23, 2009 5:29 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Quote:
I'm a newbie to hibernate search. I'm working on free text search where im indexing a filed to get skills in the following manner java,vb,j2ee. I'm able to retrieve the data from the db for all the scenarios of search except for single word search. Eg say i'm searching for java skills, i get all the results but fail to retrieve the data if it is something like j2ee,vb,java.


I am not quite sure where your problem with "j2ee,vb,java" occurs? Is this the data you want to index or is this somehow the input to your query generation method. You should also post the annotated Opportunity class so that we can see what's indexed and how.

Your query code also looks very strange. In the case where the skills string is comma separated you seem to execute a search for each skill. That won't perform very well. You should build one single query string or use the Lucene's programmatic Query API to build a single query.

In string form you want something like: " skillsNeeded: j2ee skillsNeeded: vb skillsNeeded: java title: foo " - you get the picture. Check the Lucene query syntax - http://lucene.apache.org/java/2_3_2/que ... yntax.html - for more help.

--Hardy


Top
 Profile  
 
 Post subject: Re: Hibernate search for multiple words
PostPosted: Tue Jun 23, 2009 6:11 am 
Newbie

Joined: Mon Feb 16, 2009 2:59 am
Posts: 3
Location: Bangalore
here is the opportunity class
@Indexed(index="Opportunity")

@Entity
//@PrimaryKeyJoinColumn(name="category_id")
@Table(name = "opportunity")

public class Opportunity {

@Field(index=Index.TOKENIZED, store= Store.NO)
@Field(index=Index.TOKENIZED, store= Store.NO)
private String str_location;
private Set<OpportunitySkills> opportunitySkills = new HashSet<OpportunitySkills>();
@Field(index=Index.TOKENIZED, store= Store.NO)
private String skillsNeeded;

The problem occurs when im trying to index the data. You are correct in saying that performance goes low when trying to search for each skill.

_________________
Shwetha Sharma


Top
 Profile  
 
 Post subject: Re: Hibernate search for multiple words
PostPosted: Tue Jun 23, 2009 6:23 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
If the skillsNeeded string is a comma separated string you will have to use a different analyzer. Since you have not specified an analyzer (assuming you have not defined a global default analyzer in the configuration file) the StandardAnalyzer is used. This analyzer won't tokenize the way you want. You really want to split at the ','. Using @AnalyzerDef and Solr's PatternTokenizer might be a solution. Have a look in the online manual regarding @AnalyzerDef.

--Hardy


Top
 Profile  
 
 Post subject: Re: Hibernate search for multiple words
PostPosted: Mon Jul 13, 2009 1:19 am 
Newbie

Joined: Mon Feb 16, 2009 2:59 am
Posts: 3
Location: Bangalore
Hardy,

As per your suggestions, i did try using the PatternTokenizer, however the problem still seems to persisting. I have a column in db like java,vb,j2ee. Say when i search for j2ee, the results fail to show the coulmn where j2ee is the last element.

_________________
Shwetha Sharma


Top
 Profile  
 
 Post subject: Re: Hibernate search for multiple words
PostPosted: Mon Jul 13, 2009 5:18 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Have you used Luke (http://www.getopt.org/luke/) to inspect your index and see which tokens are actually indexed? Remember, you have use Store.YES in order to see the tokens in the index. In your case you should see three values for the "java,vb,j2ee" case.

--Hardy


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