0

我正在尝试开始使用 Neo4j 和 Neo4jClient;我尝试尝试的第一件事是插入一系列具有publication_number 属性的节点。在插入每个节点之前,我想检查以确保不存在具有相同发布号的另一个节点。为此,我为publication_number 创建了一个索引,然后进行查询。

这是我到目前为止的代码。(显然上面的所有逻辑都没有实现,但我什至无法让它工作。)

class Program
{
    static void Main(string[] args)
    {
        var client = new GraphClient(new Uri("http://192.168.12.31:7474/db/data"));
        client.Connect();

        // create index
        client.CreateIndex("publication_number_idx", new IndexConfiguration
        {
            Provider = IndexProvider.lucene,
            Type = IndexType.exact
        },
        IndexFor.Node);

        // create record
        Record record1 = new Record { publication_number = "1" };
        Record record2 = new Record { publication_number = "2" };

        // add record1 to graph and index
        var record1Ref = client.Create(record1);
        client.ReIndex(record1Ref, new[] { new IndexEntry ("publication_number_idx") { { "publication_number", record1.publication_number } } });
        Console.WriteLine("Added record1 at {0}", record1Ref.Id);

        // add record2 to graph and index
        var record2Ref = client.Create( record2, 
                                        new[] { new Cites(record1Ref) { Direction = RelationshipDirection.Outgoing } },
                                        new[] { new IndexEntry("publication_number_idx") { {"publication_number", record2.publication_number } } });
        Console.WriteLine("Added record2 at {0}", record2Ref.Id);

        // 500 error here
        client.QueryIndex<Record>("publication_number_idx", IndexFor.Node, @"START n=node:publication_number_idx(publication_number = ""2"") RETURN n;");

    }

}

public class Cites : Relationship, IRelationshipAllowingSourceNode<Record>, IRelationshipAllowingTargetNode<Record>
{
    public Cites(NodeReference targetNode)
        : base(targetNode)
    {
    }

    public const string TypeKey = "CITES";

    public override string RelationshipTypeKey
    {
        get { return TypeKey; }
    }
}

我似乎成功地添加了注释和更新了索引。我可以在控制台中使用 Cypher 查询索引;但是,当我对 Neo4J 客户端使用相同的 Cypher 查询时,我在查询中收到 500 Internal Server Error。

未处理的异常:System.ApplicationException:执行请求时收到意外的 HTTP 状态。

响应状态为:500 Internal Server Error

Neo4j 的回应(可能包括有用的细节!)是:{
“异常”:“NullPointerException”、“全名”:“java.lang.NullPointerException”、“stacktrace”:[“org.apache.lucene.util.SimpleStringInterner.intern(SimpleStringInterner.java:54)”、“org.apache .lucen e.util.StringHelper.intern(StringHelper.java:39)”、“org.apache.lucene.index.Term.(Term.java:38)”、“org.apache.luce ne.queryParser.QueryParser. getFieldQuery(QueryParser.java:643)"、"org.apache.lucene.queryParser.QueryParser.Term(QueryParser.java:1436)"、"org.apache.lucene.queryParser.QueryParser.Clause(QueryParser.java:1319 )", "org.apache.lucene.queryPar ser.QueryParser.Query(QueryParser.java:1245)", "org.apache.lucene.queryParser.QueryParser.TopLevelQuery(QueryParser.java:1234)", "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.re st.web.DatabaseActions.getIndexedNodesByQuery(DatabaseActions.java:889)", "org.neo4j.server.rest.web .DatabaseActions.get IndexedNodesByQuery(DatabaseActions.java:872)”、“org.neo4j.server.rest.web.RestfulGraphDatabase.getIndexedNodesByQuery(R estfulGraphDatabase.java:707)”、“java.lang.reflect.Method.invoke(Method .java:606)", "org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)" ] } 在 Neo4jClient.GraphClient.SendHttpRequest(HttpRequestMessage request, String commandDescription,c:\TeamCity\buildAgent\work\f1c4cf3efbf1b05e\Neo4jClient\GraphClient.cs 中的 HttpStatusCode[] ex pectedStatusCodes):C:\TeamCity 中 Neo4jClient.GraphClient.QueryIndex[TNode](String indexName, IndexFor indexFor, String query) 的第 137 行\buildA gent\work\f1c4cf3efbf1b05e\Neo4jClient\GraphClient.cs:第 1168 行 Antares.Program.Main(String[] args) 在 c:\Users\Yellick Chris\Documents\Visual Studio 2012\Projects\Antares\Antare s\程序.cs:第 41 行\Users\Yellick Chris\Documents\Visual Studio 2012\Projects\Antares\Antares s\Program.cs:line 41\Users\Yellick Chris\Documents\Visual Studio 2012\Projects\Antares\Antares s\Program.cs:line 41

4

1 回答 1

1

我不确定 500 错误是关于什么的,但让您的查询正常工作的解决方案是删除“QueryIndex”调用(已过时)并将其替换为 Cypher 表示法,因此:

var query = client.Cypher
        .Start(new {n = Node.ByIndexLookup("publication_number_idx", "publication_number", "2")})
        .Return<Record>("n");

var results = query.Results;

'QueryIndex' 中使用的查询与您的格式不同,如果您查看Neo4jclient 索引文档,您需要像这样替换=with:和 wrap with之类的内容'

client.QueryIndex<Record>("publication_number_idx", IndexFor.Node, @"START n=node:publication_number_idx('publication_number: ""2""') RETURN n;");

并不是说可以修复 500 错误。

于 2013-09-27T07:32:55.623 回答