Reputation: 551
I am trying to create a hibernate full text search using hibernate-search-4.3.0.Final.jar There is no errors in this application, but my Lucene query unsing the query DSL doesn't return any results. I mean It doesn't return any of rows in the table. can any one please help me.
This is my function:
OgmConfiguration cfgogm=new OgmConfiguration();
cfgogm.configure("hibernate.cfg.xml");
serviceregistry=new ServiceRegistryBuilder().applySettings(cfgogm.getProperties()).buildServiceRegistry();
sessionfactory=cfgogm.buildSessionFactory(serviceregistry);
Session session= sessionfactory.openSession();
FullTextSession fulltextsession= Search.getFullTextSession(session);
QueryBuilder querybuilder=fulltextsession.getSearchFactory().buildQueryBuilder().forEntity(User.class).get();
org.apache.lucene.search.Query lucenequery=querybuilder.keyword().onField("IdU").matching("96645").createQuery();
org.hibernate.search.FullTextQuery fulltextquery=fulltextsession.createFullTextQuery(lucenequery, User.class);
List result=fulltextquery.list();
System.out.println(result.toString());
and this is my POJO class:
@Entity
@Table(name="Users")
@Indexed
public class User {
@Id
@GeneratedValue(generator="mongodb_uuidgg")
@Field(index = Index.YES,analyze = Analyze.NO,store = Store.NO)
private String _id;
@Column(name="City")
@Field(index = Index.YES,analyze = Analyze.NO,store = Store.NO)
private String city;
@Column(name="UserID")
@Field(index = Index.YES,analyze = Analyze.NO,store = Store.NO)
private int IdU;
...
Upvotes: 0
Views: 1677
Reputation: 19109
Have you actually indexed the data? You need to create the initial index, if you start with an existing database. You can use the programmatic index API and the mass indexer to create the initial index. Once you have the initial index and you are you use incremental indexing the index will stay in sync with database changes (provided changes are made via the Hibernate/JPA API).
Other than that have look at the lg file. Is there anything in there? If you still have the issue please post the code you use to index the data.
Upvotes: 0
Reputation: 5693
I would use Luke to verify that your queries actually return what you want from the index.
[edit...] If Luke shows that the index is empty, you will need to look at your indexing setup.
Upvotes: 2
Reputation: 78795
Most likely, the configuration for the id field is incorrect. It should be:
@Id
@GeneratedValue(generator="mongodb_uuidgg")
@DocumentId
private String _id;
(i.e. @DocumentId
instead of @Field
).
Upvotes: 1