Spring Boot Webapplication + Spring Data Jpa + Hibernate-Search - Index is not created if Repository save Method is used -
i'm developing webapplication spring boot , spring data jpa (hibernate). due need of full-text search capability integrated hibernate search engine, enities not indexed unless manual indexing by
fulltextentitymanager.createindexer().startandwait();
if manual indexing of entities works fine, if use save()-method of crudrepository index not created.
public interface jobrepositorycustom { public list<job> searchjobs(searchdto searchdto); } public class jobrepositoryimpl implements jobrepositorycustom { @persistencecontext private entitymanager entitymanager; @override public list<job> searchjobs(searchdto searchdto) { list<job> jobs; fulltextentitymanager fulltextentitymanager = org.hibernate.search.jpa.search.getfulltextentitymanager(entitymanager); /* try { fulltextentitymanager.createindexer().startandwait(); } catch (interruptedexception e) { system.out.println("an error occurred trying build serach index: " + e.tostring()); }*/ querybuilder querybuilder = fulltextentitymanager.getsearchfactory().buildquerybuilder().forentity(job.class).get(); org.apache.lucene.search.query lucenequery = querybuilder.bool().must(querybuilder.keyword().onfields("title", "introduction").matching(searchdto.getsearchterm()).createquery()).createquery(); org.hibernate.search.jpa.fulltextquery fulltextquery = fulltextentitymanager.createfulltextquery(lucenequery, job.class); jobs = fulltextquery.getresultlist(); return jobs; } } @repository public interface jobrepository extends crudrepository<job, integer>, jobrepositorycustom { }
Comments
Post a Comment