2

I have an app that I'm attempting to integrate hibernate search into. I'm using Hibernate Search 3.4.2. I have a domain class that looks like the following:

@Indexed
public Group {

    @Fieldindex (index = Index.TOKENIZED, store = Store.YES)
    private String groupName;
}

In my test cases, I create a few Groups and save them to the database. Once stored in the database, I create the index and then search for given text strings. This seems to work.

The problem I'm having is that any new Groups created after the index has been created are not indexed. From what I've read, I thought that once the index is created, any new items persisted would be automatically indexed with the new values, but this doesn't seem to be the behavior I'm getting. Is there something I've missed in the way of configuration? Or do I have to do something manually to tell Hibernate Search that I've added a new object to be indexed?

Needless to say, I'm a bit confused...



[EDIT] I'm using JPA, so my hibernate search confguration is contained in my persistence.xml as follows:

     
<property name="hibernate.search.default.directory_provider" value="filesystem"/> 
<property name="hibernate.search.default.indexBase" value="D:\var2\lucene\indexes"/>



I can see that the index files are created, and I can use Luke to view the contents, they just don't ever seem to get updated when I persist a new object.

Steve
  • 2,678
  • 8
  • 40
  • 54

1 Answers1

1

As stated in the documentation "By default, every time an object is inserted, updated or deleted through Hibernate, Hibernate Search updates the according Lucene index".

What I would do is to check my persistence.xml and see if I have not accidentally set hibernate.search.indexing_strategy = manual

If that's not the case, maybe you could try to force it and see if that works?

hibernate.search.indexing_strategy = event

Which framework are you using? Maybe check out the last post of this question.

// Jakob

Community
  • 1
  • 1
jakob
  • 5,979
  • 7
  • 64
  • 103
  • I wasn't setting that value by default. I've added the "event" indexing_strategy to the persistence.xml file, but it has no effect. – Steve May 09 '12 at 13:57
  • Trying the solution pointed to in that post, setting hibernate.search.worker.batch_size=1 seems to work. Thanks for the pointer... – Steve May 09 '12 at 14:02
  • Setting the batch_size to 1 is the wrong approach. If you do that you effectively bypass any transactional scoping. Automatic indexing should normally happen on transaction commit (all entities which have changed within this session/transaction). My guess is that your problem is somewhere in the transaction handling. You would need to post more information about your setup to get more help. – Hardy May 10 '12 at 06:24