I want to implement Fulltextsearch in MongoDB using Hibernate OGM. I wrote the code, but the code returns me an empty result. I have checked two files, which were produced by lucene with Luke, but it seems that both of them are empty. I don't know what is the cause of my problem.
I have enabled fulltext search in my collection with this command:
db.adminCommand( { setParameter : "*", textSearchEnabled : true } );
and also I have put the index on the UserID field in Users collection.
db.Users.ensureIndex({UserID:1 })
also I have this entity class:
@Entity
@Indexed
@Table(name="Users")
@GenericGenerator(name="mongodb_uuidgg",strategy = "uuid2")
public class User implements Serializable{
private static final long serialVersionUID=1L;
@DocumentId
private String id;
@Column(name="City")
@Field(index = Index.NO,analyze = Analyze.YES,store = Store.YES)
private String city;
@Column(name="UserID")
@NumericField
@Field(index = Index.YES,analyze = Analyze.NO,store = Store.YES)
private int IdU;
and in my DAO class:
OgmConfiguration cfgogm=new OgmConfiguration();
cfgogm.configure("hibernate.cfg.xml");
serviceregistry=new ServiceRegistryBuilder().applySettings(cfgogm.getProperties()).buildServiceRegistry();
sessionfactory=cfgogm.buildSessionFactory(serviceregistry);
sessionfactory.openSession();
FullTextSession fulltextsession= Search.getFullTextSession(sessionfactory.getCurrentSession());
QueryBuilder querybuilder=fulltextsession.getSearchFactory().buildQueryBuilder().forEntity(User.class).get();
org.apache.lucene.search.Query lucenequery=querybuilder.keyword().onField("IdU").matching(new Integer(87709)).createQuery();
org.hibernate.search.FullTextQuery fulltextquery=fulltextsession.createFullTextQuery( lucenequery,User.class );
fulltextquery.initializeObjectsWith(ObjectLookupMethod.SKIP, DatabaseRetrievalMethod.FIND_BY_ID);
List result=fulltextquery.list();
System.out.println(result.size());
If I open the segment.gen with Luke, I see this information:
Could you please help me to solve this problem? or how can I implement fulltext search using Hibernate and Lucene with MongoDB
thank you so much