Is this suitable to switch off/on at runtime too?
No, but at least you don't have to re-compile: your configuration code could read an environment variable, or a configuration file.
To switch indexing on/off at runtime, we have the notion of EntityIndexingInterceptor; there is a very simple example here: http://docs.jboss.org/hibernate/search/5.5/reference/en-US/html_single/#example-search-mapping-indexinginterceptor-blog
If you want to switch off temporarily the indexing of a whole entity (it won't work for single fields unfortunately) you could register such an interceptor and turn indexing off based on some @Transient entity property, for example you could add a boolean getIndex() method.
|