One of the nicest features in the new Compass version is support for annotations. Making your domain model searchable could not be simpler now if you are working with Java 5. Just how simple it is? Here is what you need to do:
First, let us assume that you have a class called Book. The book has a title, author and content. Here is the class with Compass searchable annotations:
@Searchable
public class Book { @SearchableId private Long id; @SearchableProperty
private String title; @SearchableProperty
private String author; @SearchableProperty
private String content; // rest of class
}
When designing annotations support in Compass, one of the main goals was not to create annotations clutter. As you can see, the annotations have sensible defaults, and try to be short and to the point.
Now, adding the class to Compass could not be simpler. You can either use the xml based configuration file:
<compass name=“default”> <connection>
<file path=“target/test-index” />
</connection>
<mappings>
<class name=“Book” />
</mappings>
</compass>
Or, add it programmatically to Compass Configuration:
CompassConfiguration conf = new CompassAnnotationsConfiguration()
.addClass(Book.class);
That is it. You can now use the usual Compass API in order to use the Book object.