-->
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: Hibernate Search not working properly
PostPosted: Thu Dec 01, 2011 7:24 am 
Newbie

Joined: Wed Nov 16, 2011 8:07 am
Posts: 3
Hi everybody,

I have been trying to integrate Hibernate Search in my project and everything looks fine. My problem is the results that my search returns are simply not the results I would expect. Sometime my query doesn't find anything and sometimes not all the results are found. I have no idea what I'm doing wrong here. I'd really appreciate some help. Here is my Code

String[] announcementFields = {"title", "description", "city"};
FullTextSession fSession = Search.getFullTextSession(getSession());
MultiFieldQueryParser parser = new MultiFieldQueryParser(Version.LUCENE_31, announcementFields, new StandardAnalyzer(Version.LUCENE_31));
Query luceneQuery = null;
try {
luceneQuery = parser.parse(keywords+"*");
} catch (ParseException e) {
e.printStackTrace();
}
org.hibernate.Query fullTextQuery = fSession.createFullTextQuery(luceneQuery, Announcement.class);

@Entity
@Indexed
@Table(name = "announcement")
public class Announcement implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue (strategy = GenerationType.AUTO)
@DocumentId
private int id;

@Field(name="announcementtitle", index=Index.TOKENIZED, store=Store.NO)
private String title;

@Column(length=5000)
@Field(index=Index.TOKENIZED, store=Store.NO)
private String description;

private String telephone;
private String email;
private String postCode;

@Field(index=Index.TOKENIZED, store=Store.NO)
private String city;


......

I have about 12 announcements all in the same city but when I search for that city I only get 4 results. Also when I search for a certain title I don't have any results at all. An this is the case for all the tables I'm trying to index.
The indexes were created using:
fullTextSession.createIndexer().startAndWait();

Thanks


Top
 Profile  
 
 Post subject: Re: Hibernate Search not working properly
PostPosted: Fri Dec 02, 2011 4:37 am 
Hibernate Team
Hibernate Team

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

it is hard to say what the problem is without knowing the concrete data. The code you pasted looks ok. Have you inspected you index with Luke - http://code.google.com/p/luke/ ? You can run your queries in Luke and see what happens. This cuts out Hibernate Search and might help narrow down your problem. When experimenting with Luke I often set store=Store.YES to get even more information in Luke.

What analyzer are you using for indexing ? I cannot see any analyzer configuration code in your post and unless you set a default analyzer in the Hibernate properties file the StandardAnalyzer is used. Is this what you want?

Last but not least? What are you searching for? In your code you have parser.parse(keywords+"*");. Is keywords a single word or multiple? Appending the '*' will only create a wildcard query for the last word (in case they are multiple).

Hope this helps.

--Hardy


Top
 Profile  
 
 Post subject: Re: Hibernate Search not working properly
PostPosted: Fri Dec 02, 2011 2:50 pm 
Newbie

Joined: Wed Sep 21, 2011 2:20 pm
Posts: 16
beside what Hardy said, it seems to me, that you are using two different field names:

you are querying for "title", but indexing the title as "announcementtitle"

regards


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.