lucene - Fulltext search in Mongodb using Hibernate Ogm -
i want implement fulltextsearch in mongodb using hibernate ogm. wrote code, code returns me empty result. have checked 2 files, produced lucene luke, seems both of them empty. don't know cause of problem.
i have enabled fulltext search in collection command:
db.admincommand( { setparameter : "*", textsearchenabled : true } );
and have put index on userid field in users collection.
db.users.ensureindex({userid:1 })
also have 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 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 open segment.gen luke, see information:
could please me solve problem? or how can implement fulltext search using hibernate , lucene mongodb
thank much
i not quite sure overall goal here, mixing 2 things. there built-in mongodb fulltext search capability , there hibernate ogm can use in combination hibernate search. however, 2 different things. setting mongodb parameter textsearchenabled not going create lucene index in case that's expect. need use hibernate search indexing api or mass indexer create initial index.
Comments
Post a Comment