-->
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.  [ 7 posts ] 
Author Message
 Post subject: Serious problem with Hibernate Search
PostPosted: Mon Jul 09, 2007 9:20 am 
Newbie

Joined: Fri Apr 13, 2007 2:16 am
Posts: 11
Hi
I am not getting any result when i search after indexing.
Following is the annotated java class and the test class.

Campaign.java-------
package com.XXX.javabeans;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.search.annotations.ContainedIn;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Store;

/**
* Campaign generated by hbm2java
*/
@Entity
@Table(name = "campaign")
@Indexed(index="campaign")
public class Campaign implements java.io.Serializable {

private long campaignId;

private String campaignName;

public Campaign() {
}

public Campaign(long campaignId, String campaignName) {
this.campaignId = campaignId;
this.campaignName = campaignName;
}

@Id
@Column(name = "CampaignID", unique = true, nullable = false)
@DocumentId
public long getCampaignId() {
return this.campaignId;
}

public void setCampaignId(long campaignId) {
this.campaignId = campaignId;
}

@Column(name = "CampaignName", nullable = false, length = 40)
@Field(index = Index.TOKENIZED, store = Store.YES)
public String getCampaignName() {
return this.campaignName;
}

public void setCampaignName(String campaignName) {
this.campaignName = campaignName;
}
}

TestClass---------
package com.XXX.javabeans;

import java.util.List;

import org.apache.lucene.analysis.StopAnalyzer;
import org.apache.lucene.index.Term;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;

import com.einstix.utils.HibernateUtils;

public class TestDetpEmp {

/**
* @param args
* @throws ParseException
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Session s = HibernateUtils.getCurrentSession();

Campaign obj = new Campaign();
obj.setCampaignName("sanjeet");
HibernateUtils.saveOrUpdate(obj);

System.out.println("Object successfully inserted");


FullTextSession textSession = Search.createFullTextSession(s);
QueryParser parser = new QueryParser("CampaignName", new StopAnalyzer());
org.apache.lucene.search.Query luceneQuery = parser.parse("CampaignName:sanjeet");
org.hibernate.Query fullTextQuery = textSession.createFullTextQuery(luceneQuery);

List<Object> result = fullTextQuery.list();
for (Object o : result) {
System.out.println("Result: " + o);
}

HibernateUtils.closeSession();
}
}

I not getting any exception also.
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 09, 2007 10:25 am 
Newbie

Joined: Fri Jun 29, 2007 5:01 am
Posts: 12
hi,

a stack trace would be nice...

try to search the field "campaignName" as afaik hibernate search will name the fields after the java bean introspection. also use lucene luke to inspect your index (see if there is anything indexed).[/url]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 09, 2007 12:01 pm 
Newbie

Joined: Fri Apr 13, 2007 2:16 am
Posts: 11
Actually , i am not getting any exception.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 11, 2007 1:55 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
try "campaignName:sanjeet" instead of "CampaignName:sanjeet"

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 12, 2007 7:22 am 
Newbie

Joined: Fri Apr 13, 2007 2:16 am
Posts: 11
Thanks emannuel, it really worked.

The point i learnt is that we should use field name to query rather than using column name.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 12, 2007 8:55 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
So it wasn't a Serious problem after all ;)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 13, 2007 3:20 am 
Newbie

Joined: Fri Apr 13, 2007 2:16 am
Posts: 11
Yeah, it wasn't a serious problem at all.


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