Compass has the concept of a CompassSession, which is created using the Compass instance and then used to perform indexing operation (create/save/delete) and search/read operations. In the upcoming 2.2 M2, two sub types of the CompassSession can now be used. The CompassIndexSession for indexing purposes, and the CompassSearchSesssion for search/read purposes. This can simplify a bit the usage of different sessions (less code complete clutter) , as well as allow for some optimizations to be made when choosing a specific session.
Here is how the indexing session can be used:
CompassIndexSession session = compass.openIndexSession();
try {
session.save(author);
session.delete(Author.class, 2);
session.create(book);
session.commit();
} catch (Exception e) {
session.rollback();
}
And here is how the search session can be used:
CompassSearchSession session = compass.openSearchSession();
try {
CompassHits hits = session.find("jack london");
// ...
} finally {
session.close();
}
Enjoy!.