new DynamicPropertiesEntity()
.set("name", "JavaOne 2011")
.set("city", "San Francisco")
.set("awards", "Duke Award to Arquillian")
);
SearchManager qf = Search.getSearchManager(cache);
QueryBuilder queryBuilder = qf.buildQueryBuilderForClass(DynamicPropertiesEntity.class).get();
// Searching for a specific entity:
Query query = queryBuilder
.phrase()
.onField("city")
.sentence("London")
.createQuery();
List list = qf.getQuery(query).list();
assert list.size() == 1;
DynamicPropertiesEntity result = (DynamicPropertiesEntity) list.get(0);
assert result.getProperties().get("name").equals("JUDCon London 2011");
// Search for all of them:
Query dateQuery = queryBuilder
.phrase()
.onField("name")
.sentence("2011")
.createQuery();
list = qf.getQuery(dateQuery).list();
assert list.size() == 3;
// Now search for a property define on a single entity only:
Query awardsQuery = queryBuilder
.phrase()
.onField("awards")
.sentence("Duke")
.createQuery();
list = qf.getQuery(awardsQuery).list();
assert list.size() == 1;
result = (DynamicPropertiesEntity) list.get(0);
assert result.getProperties().get("city").equals("San Francisco");
}