【问题标题】:Integer index behavior in neo4j + luceneneo4j + lucene 中的整数索引行为
【发布时间】:2012-09-28 23:20:56
【问题描述】:

我想在大型数据库(约 2000 万个节点)的节点上索引一个整数字段。我希望工作的行为如下:

HashMap<String, Object> properties = new HashMap<String, Object>();

// Add node to graph (inserter is an instance of BatchInserter)
properties.put("id", 1000);
long node = inserter.createNode(properties);

// Add index 
index.add(node, properties);

// Retrieve node by index. RETURNS NULL!
IndexHits<Node> hits = index.query("id", 1000);

我将键值对添加到索引中,然后通过它进行查询。可悲的是,这不起作用。

我目前的 hackish 解决方法是使用 Lucene 对象并按范围查询:

// Add index 
properties.put("id", ValueContext.numeric(1000).indexNumeric());
index.add(node, properties);

// Retrieve node by index. This still returns null
IndexHits<Node> hits = index.query("id", 1000);

// However, this version works
hits = index.query(QueryContext.numericRange("id", 1000, 1000, true, true));

这是完美的功能,但范围查询真的很愚蠢。有没有办法在没有 QueryContext.numericRange 混乱的情况下运行精确的整数查询?

【问题讨论】:

    标签: lucene indexing neo4j


    【解决方案1】:

    您需要的索引查找是完全匹配,而不是查询。

    尝试替换 index.query("id", 1000)index.get("id", 1000)

    【讨论】:

    • 如果您取消 ValueContext 对象,这将有效。您失去了按范围查询的能力,但这与我的情况无关。谢谢!
    猜你喜欢
    • 2015-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-11
    • 2013-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多