Neo4j 搜索对象集合

Neo4j 搜索对象集合,neo4j,neo4jclient,Neo4j,Neo4jclient,我正在尝试搜索潜在节点的集合,但无法执行此操作。。。 我有一个产品,它与许多实例都有关系。我想查询数据库并从用户那里获取列表中的所有实例 密码: var query = _context .Cypher .Start(new { instance = startBitsList, product = productNode.Reference, }) .Match("(product)-[:HasInstanceRel]->(instance)") .Return(

我正在尝试搜索潜在节点的集合,但无法执行此操作。。。 我有一个产品,它与许多实例都有关系。我想查询数据库并从用户那里获取列表中的所有实例

密码:

var query = _context
 .Cypher
 .Start(new
 {
   instance = startBitsList,
   product = productNode.Reference,
 })
 .Match("(product)-[:HasInstanceRel]->(instance)")
 .Return(instance => instance.Node<ProductInstance>());
var查询=\u上下文
塞弗先生
.开始(新)
{
instance=startBitsList,
product=productNode.Reference,
})
.Match(“(产品)-[:HasInstanceRel]->(实例)”)
.Return(instance=>instance.Node());
问题是startBitsList。。。我使用StringBuilder生成一个查询,其中包含我要查找的所有实例:

private static string CreateStartBits(IEnumerable<string> instanceNames)
 {
   var sb = new StringBuilder();
   sb.AppendFormat("node:'entity_Name_Index'(");
   foreach (var id in productIds)
   {
     sb.AppendFormat("Name={0} OR ", id);
   }
   sb.Remove(sb.Length - 4, 4);
   sb.Append(")");

  var startBitsList = sb.ToString();
  return startBitsList;
}
私有静态字符串CreateStartBits(IEnumerable instanceNames)
{
var sb=新的StringBuilder();
sb.AppendFormat(“节点:'entity_Name_Index'(”);
foreach(productIds中的变量id)
{
sb.AppendFormat(“Name={0}或”,id);
}
移除(sb长度-4,4);
某人加上(“)”;
var startBitsList=sb.ToString();
返回startBitsList;
}
我在尝试运行此密码时遇到异常。。。
有没有更好的方法来搜索我从用户那里获得的收藏中存储的多个项目?

好的,我认为这里有几个问题,首先我假设您使用的是Neo4j 1.9而不是2.0-因此使用的是
.Start

您是否尝试过使用Neo4j进行查询并运行它?这应该是您的第一个调用端口,通常很容易在
.Results
调用上添加断点,并为
query.query.DebugText
添加“监视”

但是,我不认为您需要使用StartBits。因为您已经有了起点,所以我认为您最好使用
进行过滤

private static ICypherFluentQuery CreateWhereClause(ICypherFluentQuery query, ICollection<string> instanceNames)
{
    query = query.Where((Instance instance) => instance.Name == instanceNames.First());
    query = instanceNames.Skip(1).Aggregate(query, (current, localInstanceName) => current.OrWhere((Instance instance) => instance.Name == localInstanceName));
    return query;
}
专用静态ICypherFluentQuery CreateWhere子句(ICypherFluentQuery查询,ICollection instanceNames)
{
query=query.Where((Instance实例)=>Instance.Name==instanceNames.First());
query=instanceNames.Skip(1).Aggregate(查询,(当前,localInstanceName)=>current.OrWhere((实例实例)=>Instance.Name==localInstanceName));
返回查询;
}
您的查询会变成类似于:

var prodReference = new NodeReference<Product>(2);

var query =
    Client.Cypher
        .ParserVersion(1, 9)
        .Start(new {product = prodReference})
        .Match("(product)-[:HasInstanceRel]->(instance)");

query = CreateWhereClause(query, new[] {"Inst2", "Inst1"});
var resultsQuery = query.Return(instance => instance.As<Node<Instance>>());
var prodReference=新节点引用(2);
变量查询=
客户,塞弗
.ParserVersion(1,9)
.Start(新的{product=prodReference})
.Match(“(产品)-[:HasInstanceRel]->(实例)”);
query=createwhere子句(查询,新[]{“Inst2”,“Inst1”});
var resultsQuery=query.Return(instance=>instance.As());
2件值得注意的事情

  • 我们不使用索引-使用它们没有任何好处,因为您有了起点,对Neo4j来说,遍历“实例”是一个简单的过程

  • 如果传入空列表,则“CreateWhere子句”方法可能会出错:)


  • 不使用索引的好处是——因为它们是传统的——您为Neo4j 2.0设置得更好

    实例可以独立于产品吗?例如,您是否可以让实例“x”未连接到一个产品,或者一个实例可以连接到多个产品?每个实例必须仅连接到一个产品您是否在neo4j中尝试过该查询?如果您执行以下操作,该查询是否有效:
    START instance=/*多索引查找*/
    ??