Search in sleep mode @IndexedEmbedded

I have the same situation as this

@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; ... } 

Now the problem is this: If I change, for example, the name field in the Place entity, which objects will be reindexed?

1) Only the name field?

2) The whole Place object?

3) The entire Place object and objects annotated with @IndexedEmbedded?

The one I need for my purpose will be the third. So if this is not a standard, can there be some solution to achieve this behavior?

+4
source share
2 answers

Fortunately, this is really the third one, so I got lucky and it works as expected

+4
source

You can use the following code to re-index the place object manually

 public void updateIndex(T entity){ FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em); fullTextEntityManager.index(entity); fullTextEntityManager.getSearchFactory().optimize(entity.getClass()); } 

Secondly, if you use hibernation, you can configure lucene in persistence.xml to automatically update the indexes of entities that have changed

0
source

All Articles