Reputation: 4046
I have a similar situation like this one
@Entity
@Indexed
public class Place {
@Id
@GeneratedValue
@DocumentId
private Long id;
@Field( index = Index.TOKENIZED )
private String name;
@OneToOne( cascade = { CascadeType.PERSIST, CascadeType.REMOVE } )
@IndexedEmbedded
private Address address;
....
}
@Entity
public class Address {
@Id
@GeneratedValue
private Long id;
@Field(index=Index.TOKENIZED)
private String street;
@Field(index=Index.TOKENIZED)
private String city;
@ContainedIn
@OneToMany(mappedBy="address")
private Set<Place> places;
...
}
The problem now is the following: If I change for example the name field in entity Place which entities are going to be re-indexed?
1) Only the name field?
2) The whole Place entity?
3) The whole Place entity and the entities annotated with @IndexedEmbedded?
The one I need for my purpose would be the third. So if it is not standard, could there be any solution to achieve this behaviour?
Upvotes: 5
Views: 6266
Reputation: 5954
You can use the following code to re-index the Place Entity manually
public void updateIndex(T entity){
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);
fullTextEntityManager.index(entity);
fullTextEntityManager.getSearchFactory().optimize(entity.getClass());
}
Secondly if you are using hibernate you can configure lucene in persistence.xml
to automatically update the indexes of the entities that are changed
Upvotes: 0
Reputation: 4046
Fortunately it's really the third, so I was lucky and it works as expected
Upvotes: 4