Показаны сообщения с ярлыком hibernate. Показать все сообщения
Показаны сообщения с ярлыком hibernate. Показать все сообщения

понедельник, 9 января 2012 г.

Hibernate Search re-index

I had to solve problem with re-indexing recipes for my own russian cooking portal cook365.ru when I add new entries from MySql dump to database on live server. So I added this method in my service implementation class.

    @Transactional
    public List<Recipe> reindexAll() {

        List<Recipe> recipes = recipeDao.findAll();

        EntityManager entityManager = entityManagerFactory.createEntityManager();

        FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);

        for (Recipe recipe : recipes) {

            recipe = fullTextEntityManager.merge(recipe);

            fullTextEntityManager.index(recipe);

        }

        fullTextEntityManager.flushToIndexes();

        return recipes;

    }



At first time I didn't added fullTextEntityManager.flushToIndexes(); and indexes were not updated, spent some time to figure out the problem.