Question

I am using Compass for filtering data out from a DTO object. I mark fields with @SearchableComponent if it is a POJO object, with SearchableProperty if it is a String. That works perfectly: I get the object and String indexed.

My question is how would I annotate an ENUM data type?

Example of enums I have:

public enum FooBar {
    FOO("foo"),
    BAR("bar");
    private final String value;

    ..(constructor)..

    public String value() {
        return value;
    }
}

Where in this snippet I should put an annotation and which annotation I should put?

Was it helpful?

Solution

From version 2.1 forward this works out of the box using @SearchableProperty annotation to the field that is of the type of this enum eg.

    @SearchableProperty    
    FooBar foobar;

Search uses enum name as the returned type of filtering. Dealing with the value thing that was on the question is to be handled after search is made with names.

See release notes of Compass 2.1.0.

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