在Geode中創建了一個Lucene索引,其代碼在documentation中提供。然後在該區域放置幾個對象,並用Lucene查詢查詢該區域,該文檔還顯示了該方法。但查詢結果始終爲空。這裏是我的代碼:查詢在Apache Geode中創建的Lucene索引
啓動的Geode服務器並創建它Lucene索引:在區域和查詢
public static void startServerAndLocator() throws InterruptedException {
ServerLauncher serverLauncher = new ServerLauncher.Builder()
.setMemberName("server1")
.setServerPort(40404)
.set("start-locator", "127.0.0.1[10334]")
.build();
ServerLauncher.ServerState state = serverLauncher.start();
_logger.info(state.toString());
Cache cache = new CacheFactory().create();
createLuceneIndex(cache);
cache.createRegionFactory(RegionShortcut.PARTITION).create("test");
}
public static void createLuceneIndex(Cache cache) throws InterruptedException {
LuceneService luceneService = LuceneServiceProvider.get(cache);
luceneService.createIndexFactory()
.addField("fullName")
.addField("salary")
.addField("phone")
.create("employees", "/test");
}
把對象:
public static void testGeodeServer() throws LuceneQueryException, InterruptedException {
ClientCache cache = new ClientCacheFactory()
.addPoolLocator("localhost", 10334)
.create();
Region<Integer, Person> region = cache
.<Integer, Person>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create("test");
List<Person> persons = Arrays.asList(
new Person("John", 3000, 5556644),
new Person("Jane", 4000, 6664488),
new Person("Janet", 3500, 1112233));
for (int i = 0; i < persons.size(); i++) {
region.put(i, persons.get(i));
}
LuceneService luceneService = LuceneServiceProvider.get(cache);
LuceneQuery<Integer, Person> query = luceneService.createLuceneQueryFactory()
.setLimit(10)
.create("employees", "/test", "fullName:John AND salary:3000", "salary");
Collection<Person> values = query.findValues();
System.out.println("Query results:");
for (Person person : values) {
System.out.println(person);
}
cache.close();
}
人是一個基本的POJO類有三個字段(姓名,工資,電話)。 我在這裏做錯了什麼?爲什麼查詢結果是空的?