0

我想知道如何构建一个 Cypher 查询,该查询将使用 spring data neo4j 结合全文和简单索引。考虑以下节点实体:

@NodeEntity
public class SomeObject {

    public SomeObject() {

    }

    public SomeObject(String name, int height) {
        this.name = name;
        this.height = height;
    }

    @Indexed(indexType = IndexType.FULLTEXT, indexName = "search_name")
    String name;

    @Indexed(numeric = false)
    int height;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

好的,所以我的问题是我如何运行SomeObjectSomeObject节点开始的查询(通过使用图形存储库),通过在同一查询中引用它们的简单索引和全文索引。例如我想写这样的东西:

START n=node:SomeObject('name: Roy AND height: [170 TO 190]') RETURN n

我知道我不能完全那样写,因为 spring data neo4j 迫使我为需要 FULLTEXT 索引的字段提供单独的索引名称。但是,如果我需要为SomeObject结合了两个文件的实体进行索引查找怎么办?(姓名和身高)

在这种情况下,最佳做法是什么?有没有办法将它们组合在同一个查询中?或者也许我应该分别查询它们中的每一个,然后在两个结果之间执行某种交集,所以我会得到完全符合我原始查询查找条件的节点?( name: Roy AND height: [170 TO 190])。

谢谢!罗伊。

4

1 回答 1

1

I'd never launch two separate queries. Maybe just use one index as a starting point in your query?

START n=node:search_name('name: Roy')
WHERE n.height >= 170 AND n.height <= 190
RETURN n

How's the performance of this query? This bypasses the SomeObject index, but I don't see any other option as you indeed cannot combine both indexes.

I as also thinking about the following query, but you'd still end up with duplicates:

START n=node:search_name('name: Roy'), m=node:SomeObject('height: [170 TO 190]')
RETURN DISTINCT n,m
于 2013-05-07T13:19:46.807 回答