I'm developing a Webapplication with Spring Boot and Spring Data Jpa (Hibernate). Due to the need of a full-text search capability I integrated the Hibernate Search Engine, but the Enities are not indexed unless I do a manual indexing by

fullTextEntityManager.createIndexer().startAndWait();

If I do the manual indexing of all Entities then everything works fine, but if I use the save()-Method of the CrudRepository then the index is 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 to build the 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 {
}
0

There are 0 best solutions below