質問

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

}
役に立ちましたか?

解決

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.

他のヒント

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top