5

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?

2 Answers 2

4

Fortunately it's really the third, so I was lucky and it works as expected

Sign up to request clarification or add additional context in comments.

Comments

0

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

2 Comments

Actually that's not what I'm lookin for. I was interested in the automatic process
Can you give an example of this configuration?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.