1

我正在使用 Neo4j-community-1.9.M04,与 python rest 客户端(py2neo 1.4.5)连接。当我尝试向索引添加长文本时,服务器返回 500 Internal Server Error。

使用 py2neo 客户端,我喜欢:

everything_idx = gdb.get_or_create_index(neo4j.Node, "everything", config={"type": "fulltext"})
everything_idx.add("everything", long_text, recommendation_node)

其中 long_text 是一个包含从 URL 解析的文本的变量,而 Recommendation_node 是我要索引的 Node 实例。

这是我在 py2neo 日志中的内容:

INFO 2013-03-05 11:47:17,855 rest 11104 1108 POST /db/data/index/node/everything {'Content-Type': 'application/json', 'X-Stream': 'true', 'Accept': 'application/json', 'User-Agent': 'py2neo/1.4.6 (win32; python/2.7.2)'} (47486 bytes)
INFO 2013-03-05 11:47:17,894 rest 11104 1108 500 Internal Server Error {'content-length': '0', 'server': 'Jetty(6.1.25)'}

在 Neo4j 日志中,我有以下内容:console.log:

11:47:19.733 [1695422617@qtp-1319007734-22] WARN  org.mortbay.log - header full: java.lang.ArrayIndexOutOfBoundsException
11:47:19.734 [1695422617@qtp-1319007734-22] ERROR org.mortbay.log - /db/data/index/node/everything
javax.ws.rs.WebApplicationException: null
        at org.neo4j.server.rest.repr.OutputFormat$1.write(OutputFormat.java:156) ~[neo4j-server-1.9.M04.jar:1.9.M04]
        at com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider.writeTo(StreamingOutputProvider.java:71) ~[jersey-core-1.9.jar:1.9]
        at com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider.writeTo(StreamingOutputProvider.java:57) ~[jersey-core-1.9.jar:1.9]
        at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:306) ~[jersey-server-1.9.jar:1.9]
        at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1437) ~[jersey-server-1.9.jar:1.9]
        at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349) ~[jersey-server-1.9.jar:1.9]
        at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339) ~[jersey-server-1.9.jar:1.9]
        at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416) ~[jersey-server-1.9.jar:1.9]
        at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) ~[jersey-server-1.9.jar:1.9]
        at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699) ~[jersey-server-1.9.jar:1.9]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) ~[servlet-api-2.5-20081211.jar:na]
        at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) ~[jetty-6.1.25.jar:6.1.25]
        at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390) ~[jetty-6.1.25.jar:6.1.25]
        at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) [jetty-6.1.25.jar:6.1.25]
        at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) [jetty-6.1.25.jar:6.1.25]
        at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114) [jetty-6.1.25.jar:6.1.25]
        at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) [jetty-6.1.25.jar:6.1.25]
        at org.mortbay.jetty.Server.handle(Server.java:326) [jetty-6.1.25.jar:6.1.25]
        at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) [jetty-6.1.25.jar:6.1.25]
        at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:943) [jetty-6.1.25.jar:6.1.25]
        at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756) [jetty-6.1.25.jar:6.1.25]
        at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218) [jetty-6.1.25.jar:6.1.25]
        at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) [jetty-6.1.25.jar:6.1.25]
        at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410) [jetty-6.1.25.jar:6.1.25]
        at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582) [jetty-util-6.1.25.jar:6.1.25]

在 neo4j.0.0.log 中:

Mar 5, 2013 11:47:19 AM com.sun.jersey.server.impl.application.WebApplicationImpl _handleRequest
SEVERE: The response of the WebApplicationException cannot be utilized as the response is already committed. Re-throwing to the HTTP container
javax.ws.rs.WebApplicationException
        at org.neo4j.server.rest.repr.OutputFormat$1.write(OutputFormat.java:156)
        at com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider.writeTo(StreamingOutputProvider.java:71)
        at com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider.writeTo(StreamingOutputProvider.java:57)
        at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:306)
        at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1437)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
        at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
        at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
        at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
        at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
        at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
        at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
        at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
        at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
        at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
        at org.mortbay.jetty.Server.handle(Server.java:326)
        at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
        at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:943)
        at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
        at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
        at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
        at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
        at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

我认为问题可能是我正在使用的其余客户端,所以我更改了它(我首先尝试了 neo4jrestclient)。

有任何想法吗?

4

1 回答 1

1

事实证明,将此节点添加到全文索引失败的原因是它没有在事务中执行。我尝试使用以下代码,将 neo4jrestclient 与事务一起使用,它可以工作:

import urllib2, logging, logging.config, pdb, traceback
from neo4jrestclient.client import GraphDatabase, Node, Relationship

gdb = GraphDatabase("http://localhost:7474/db/data/")

everything_idx = gdb.nodes.indexes.create("everything_", type="fulltext", provider="lucene")
node = gdb.node(name="Node1")

with gdb.transaction() as tx:
    try:
        request = urllib2.urlopen("http://www.tripadvisor.com/Restaurant_Review-g35805-d451303-Reviews-Ramova_Grill-Chicago_Illinois.html")

        if request.getcode() == 200:
            long_text = unicode(request.read(), "utf-8")
            everything_idx["everything"][long_text] = node
    except Exception as e:
        pdb.set_trace()
于 2013-03-07T09:54:35.347 回答