我尝试使用Neo4jClient for .NET在Neo4j中对我的NameIndex执行查询,但是我收到此错误:
{"Received an unexpected HTTP status when executing the request.\r\n\r\nThe response status was: 500 Internal Server Error\r\n\r\nThe raw response body was: {\"exception\":\"NullPointerException\",\"stacktrace\":[\"org.apache.lucene.util.SimpleStringInterner.intern(SimpleStringInterner.java:54)\",\"org.apache.lucene.util.StringHelper.intern(StringHelper.java:39)\",\"org.apache.lucene.index.Term.<init>(Term.java:38)\",\"org.apache.lucene.queryParser.QueryParser.getFieldQuery(QueryParser.java:643)\",\"org.apache.lucene.queryParser.QueryParser.Term(QueryParser.java:1421)\",\"org.apache.lucene.queryParser.QueryParser.Clause(QueryParser.java:1309)\",\"org.apache.lucene.queryParser.QueryParser.Query(QueryParser.java:1237)\",\"org.apache.lucene.queryParser.QueryParser.TopLevelQuery(QueryParser.java:1226)\",\"org.apache.lucene.queryParser.QueryParser.parse(QueryParser.java:206)\",\"org.neo4j.index.impl.lucene.IndexType.query(IndexType.java:300)\",\"org.neo4j.index.impl.lucene.LuceneIndex.query(LuceneIndex.java:227)\",\"org.neo4j.server.rest.web.DatabaseActions.getIndexedNodesByQuery(DatabaseActions.java:977)\",\"org.neo4j.server.rest.web.DatabaseActions.getIndexedNodesByQuery(DatabaseActions.java:960)\",\"org.neo4j.server.rest.web.RestfulGraphDatabase.getIndexedNodesByQuery(RestfulGraphDatabase.java:692)\",\"java.lang.reflect.Method.invoke(Unknown Source)\"]}"}
我的方法如下:
public IEnumerable GraphGetNodeByName(string NodeName)
{
GraphOperationsLogger.Trace("Now entering GraphGetNodeByName() method");
IEnumerable QueryResult = null;
GraphOperationsLogger.Trace("Now performing the query");
var query = client_connection.QueryIndex<GraphNode>("NameIndex", IndexFor.Node,
//Here I want to pass in the NodeName into the query
//@"Start n = node:NameIndex(Name = '"+ NodeName +"') return n;");
//Here I am hard-coding the NodeName
@"Start n = node:NameIndex(Name = ""Mike"") return n;");
QueryResult = query.ToList();
return QueryResult;
}
我理想地希望将NodeName传递给查询但是这不起作用因此我尝试了硬编码并且也不起作用。两种情况都会产生相同的错误消息吗?
答案 0 :(得分:3)
您要调用的方法IGraphClient.QueryIndex
不是Cypher方法。它是http://docs.neo4j.org/chunked/milestone/rest-api-indexes.html#rest-api-find-node-by-query的包装器。这是一个较旧的API,从Cypher存在之前开始。
你已经走了一半,因为你的代码评论包括Cypher查询:
Start n = node:NameIndex(Name = "Mike")
return n;
所以,让我们把它翻译成C#:
client
.Cypher
.Start(new CypherStartBitWithNodeIndexLookup("n", "NameIndex", "Name", "Mike"))
.Return<Node<Person>>("n");
始终从IGraphClient.Cypher
或NodeReference.StartCypher
启动您的Cypher查询(这只是前者的快捷方式)。
您的方法还存在其他一些问题:
IEnumerable
。里边啥啊?您应该返回IEnumerable<T>
。query.ToList()
。如果这甚至可以编译,我会感到惊讶。您希望在结果上调用ToList
,以便枚举可枚举。camelCase
而不是PascalCase
。也就是说,queryResult
代替QueryResults
。结合所有这些点,您的方法应该是:
public IEnumerable<Person> GetPeopleByName(string name)
{
return graphClient
.Cypher
.Start(new CypherStartBitWithNodeIndexLookup("n", "NameIndex", "Name", "Mike"))
.Return<Node<Person>>("n")
.Results
.ToList();
}