此内容没有您所选择的语言版本。

15.8. Querying Example


15.8.1. The Query Module Example

The following provides an example of how to set up and run a query in JBoss Data Grid.
In this example, the "Person" object has been annotated using the following:
@Entity @ProvidedId @Indexed
public class Person
	implements Serializable {
		@Field(store = Store.YES)
		private String name;
		@Field
		private String description;
		@Field(store = Store.YES)
		private int age;
...
}
Copy to Clipboard Toggle word wrap
Assuming several of these "Person" objects have been stored in JBoss Data Grid, they can be searched using querying. The following code creates a SearchManager and QueryBuilder instance:
SearchManager manager=
	Search.getSearchManager(cache);
QueryBuilder builder=
	sm.buildQueryBuilderForClass(Person.class) .get();
Query luceneQuery = builder.keyword()
			.onField("name")
			.matching("FirstName")
		.createQuery();
Copy to Clipboard Toggle word wrap
The SearchManager and QueryBuilder are used to construct a Lucene query. The Lucene query is then passed to the SearchManager to obtain a CacheQuery instance:
CacheQuery query = manager.getQuery(luceneQuery);
for (Object result: query) {
        System.out.println("Found " + result);
}
Copy to Clipboard Toggle word wrap
This CacheQuery instance contains the results of the query, and can be used to produce a list or it can be used for repeat queries.

Important

The Query Module is currently only available as a Technical Preview for JBoss Data Grid 6.1.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat