3

假设我在 IMap 中有以下值:

public class Employee{
  public int empId;
  public List<String> categories;

  public List<String> getCategories(){
    return this.categories;
  }
}

我想找到属于“销售”类别的所有员工。另外,我想在 getCategories() 上创建一个索引,以便查询快速返回。似乎没有可用的谓词来执行此操作。我该如何实现这一目标?看来我将不得不写一个谓词来做到这一点。是否有可以查看的示例代码向我展示如何构建使用索引的谓词?

4

2 回答 2

1

我尝试将 List 迭代到单独的 Imap,然后在客户端中查询它。

IMap<String,ArrayList< categories >> cache=hazelcastInstance.getMap("cache");                   
        IMap<String, categories> cachemodified = hazelcastInstance.getMap("cachemodified") ;        
        int[] idx = { 0 };
        xref.get("urkey").forEach(cachefelement ->{
            cachemodified.put(String.valueOf(idx[0]++),cachefelement);
        });
        Predicate p = Predicates.equal("categoryId", "SearchValue");
        Collection<categories> result = cachemodified.values(p);
于 2020-08-16T01:05:18.500 回答
1

我目前看到这种情况发生的唯一方法是对数据模型进行非规范化并使用 IMap 之类的东西作为值:

class EmployeeCategory{int employeeId, String category}

并在类别上放置一个索引。

它在积压的某个地方提供更多的进步指数,应该能够开箱即用地做到这一点。

于 2015-10-14T10:24:35.383 回答