Question

If I have the following class, would I be adding both fields to the same name Lucene index or would one overwrite the other?

public User {

    @Field(name="name",store = Store.YES)
    public String getDecoratedName() {
        return name + " foobar";
    }

    @Field(store = Store.YES)
    public String getName() {
        return name;
    }

}
Was it helpful?

Solution

The underlying data structure in Lucene is a so called Document which is basically a list of Fieldables. A Fieldable is basically a key/value pair. You can have multiple fields with the same key.

So to answer your question, in your scenario there will be two fields both with the same key ('name'). The value differs of course.

OTHER TIPS

You would be adding both. Which implies a query on field "name" would match if either of the two matches. You probably want to keep them separate to have the flexibility of picking which one you want to target during a query: you can easily target both if needed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top