【问题标题】:Hazelcast - query collections of Map valuesHazelcast - 查询地图值的集合
【发布时间】:2015-09-29 19:04:35
【问题描述】:

假设我在 IMap 中有以下值:

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

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

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

【问题讨论】:

  • @pveentjer,你能回答这个问题吗?

标签: hazelcast distributed-cache hazelcast-imap


【解决方案1】:

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

class EmployeeCategory{int employeeId, String category}

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

它在积压工作中的某个地方提供了更多应该能够开箱即用地执行此操作的高级索引。

【讨论】:

  • 感谢您的回复。是否有任何积压也可以为多图添加索引?我认为这在这样的场景中会有很大的帮助。
  • Afaik 没有这样的问题。随意制作 github 票或自己进行实现 :)
  • 将密码发送给hazelcast.org/t-shirts,我会完成实施;)
【解决方案2】:

我尝试将 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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-06
    • 2011-10-05
    相关资源
    最近更新 更多