Neo4J 1.9.1的替代IndexProvider [英] Alternative IndexProvider for Neo4J 1.9.1

查看:55
本文介绍了Neo4J 1.9.1的替代IndexProvider的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中使用了Lucene 4,并且不想更改它.我正在尝试集成Neo4J,该捆绑了Lucene 3.5作为IndexProvider实现,neo4j-lucene-index.

I'm using Lucene 4 in my application and don't want to change this. I'm trying to integrate Neo4J which bundles Lucene 3.5 as an IndexProvider implementation, neo4j-lucene-index.

不幸的是,neo4j-lucene-index无法正常工作,并且排除了这种依赖性,该应用程序在启动时会无限期地挂起.我已经尝试过neo4j-lucene4-index,但是似乎不能很好地维护它,因此需要进行相当大的更新才能与Neo4J 1.9.1一起使用.这些变化远远超出了我对Neo4J内部的理解.

Unfortunately, neo4j-lucene-index does not work, and with that dependency excluded, the app just hangs indefinitely on start up. I've tried neo4j-lucene4-index but that does not seem to be maintained very well and needs to be updated quite significantly to work with Neo4J 1.9.1. The changes go way beyond my understanding of the internals of Neo4J.

但是,我可以看到IndexProviders是可插拔的,因此我希望有Lucene的现有替代品-虽然目前无法找到.谁能指出我正确的方向?

However, I can see that IndexProviders are pluggable, so I'm hoping that there is an existing alternative to Lucene - I can't find it at the moment though. Can anyone point me in the right direction for one?

Lucene 4已经推出了这么长时间似乎很奇怪,而Neo4J不支持它.我想念什么吗?

It seems strange that Lucene 4 has been out for so long now and Neo4J doesn't support it. Am I missing something?

当前,对于我的Neo4J配置,我的POM如下所示:

Currently, my POM looks like this for my Neo4J config:

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-neo4j</artifactId>
    <version>2.2.1.RELEASE</version>
    <exclusions>
        <exclusion>
        <artifactId>neo4j</artifactId>
        <groupId>org.neo4j</groupId>
        </exclusion>
        <exclusion>
        <artifactId>neo4j-cypher</artifactId>
        <groupId>org.neo4j</groupId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-kernel</artifactId>
    <version>1.9.1</version>
    <exclusion>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-lucene-index</artifactId>
    </exclusion>
</dependency>

<dependency>
    <groupId>org.neo4j.app</groupId>
    <artifactId>neo4j-server</artifactId>
    <version>1.9.1</version>
    <exclusions>
        <exclusion>
        <artifactId>neo4j</artifactId>
        <groupId>org.neo4j</groupId>
        </exclusion>
        <exclusion>
        <artifactId>neo4j-cypher</artifactId>
        <groupId>org.neo4j</groupId>
        </exclusion>
        <exclusion>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-lucene-index</artifactId>
        </exclusion>
    </exclusions>
</dependency>

    <!-- A temporary dependency until Neo4J builds in support for Lucene 4. 
    Looks like they're planning to incorporate this project anyway This project 
    is available on GitHub, and needs to be built with: mvn license:format mvn 
    install to install into your local repo. 
        <dependency>
            <groupId>com.keatext</groupId>
            <artifactId>neo4j-lucene4-index</artifactId>
            <version>1.9.M01-SNAPSHOT</version>
        </dependency>-->

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>5.0.1.Final</version>
</dependency>

推荐答案

前段时间,我也遇到了这个问题:我正在研究原型,我真的很喜欢Neo4j的嵌入式模式.但是,一旦我决定使用Lucene 4,我就迷失了兼容性.

Some time ago, I was also faced with this issue: I was working on prototyping, and I really liked embedded mode of Neo4j. But, once I decided to use Lucene 4 - I was stumbled with incompatibility issue.

OSGi

如此处建议的那样:如何在我的Java项目中使用两个版本的jar -一种可能的解决方案是使用 OSGi ,然后将Neo4j和Lucene 4包装到不同的包中.每个捆绑包将具有单独的类加载器-因此Neo4j将在Lucene 3的运行时类中使用,但是您仍然可以出于自己的目的使用Lucene 4.

As been suggested here: How to use two versions of jar in my java project - one of the possible solution is to use OSGi, and wrap Neo4j and Lucene 4 into different bundles. Each bundle will have separate classloader - so Neo4j will use in runtime classes from Lucene 3, but you still be able to use Lucene 4 for your purposes.

但是,就我从事原型开发而言-我不想因为两个组件不兼容的单一原因而花时间在我的项目上以适应OSGi平台.

But, as far as I was working on prototyping - I didn't want to spend time on adaptation of my project for OSGi platform by the single reason of incompatibility of two components.

Maven Shade插件

因此,我已经通过 Maven Shade插件.

Maven Shade插件提供了一种将所有依赖项合并到单个胖" JAR(也称为超级JAR")中的功能.

Maven Shade Plugin provides an ability to merge all dependencies into single "fat" JAR (also, called "uber JAR").

因此,您可以生成超级Neo4j依赖项",并在项目中使用它,而不是真正的" Neo4j依赖项.

So, you can generate "uber Neo4j dependency", and use it in your project - instead of "real" Neo4j dependency.

但是还有一个重要的时刻:Lucene 3和Lucene 4具有相同的包结构,并且许多类仍然具有相同的名称.因此,这可能会导致类加载冲突.

But there is an additional important moment: Lucene 3 and Lucene 4 has the same package structure, and many classes still have the same names. So, this might cause classloading conflicts.

为解决此问题,Maven Shade插件提供了在生成超级JAR"期间重定位类的功能:

To address this issue, Maven Shade Plugin provides an ability to relocate classes during generation of of "uber JAR": http://maven.apache.org/plugins/maven-shade-plugin/examples/class-relocation.html

您可以指定程序包名称,并在打包过程中- Shade插件会将类从指定的程序包及其子程序包移至其他程序包,并将重写受影响的字节码.

You can specify package name, and during packaging - Shade Plugin will move classes from specified package and its subpackages to some other package, and will rewrite affected bytecode.

因此,在为Neo4j编写超级JAR"期间-您可以配置Shade插件将Lucene 3的类移至其他软件包,例如:

So, during composing of "uber JAR" for Neo4j - you can configure Shade Plugin to move classes of Lucene 3 to some other package, e.g.:

org.apache.lucene.* -> shaded_3_6_2.org.apache.lucene.*

(幸运的是,Neo4j在应用到Lucene的东西中似乎没有使用反射).

(Luckily, it seems that Neo4j doesn't use reflection, in application to Lucene stuff).

因此,您可以使用以下pom.xml创建空的Maven项目:

So, you can create empty maven project with following pom.xml:

    <project
    xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>my.hack</groupId>
    <artifactId>uber-neo4j</artifactId>
    <version>1.9.3</version>
    <packaging>jar</packaging>
    <name>uber-neo4j</name>

    <properties>
        <neo4j-version>1.9.3</neo4j-version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j</artifactId>
            <version>${neo4j-version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                            <relocations>
                                <relocation>
                                    <pattern>org.apache.lucene</pattern>
                                    <shadedPattern>shaded_lucene_3_6_2.org.apache.lucene</shadedPattern>
                                </relocation>
                            </relocations>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>neo4j-repo</id>
            <name>Neo4j Repository</name>
            <url>http://m2.neo4j.org/content/repositories/releases</url>
        </repository>
    </repositories>
</project>

描述的配置-提供了使用更名为Lucene 3的软件包为Neo4j生成超级JAR"的能力(只需执行mvn install).

Described configuration - provides an ability to generate "uber JAR" for Neo4j with renamed packages of Lucene 3 (just do mvn install).

最后,您可以将这些东西作为模块附加到您的maven项目中.

And, finally, you can attach this stuff as a module to your maven project.

因此,在解决此问题后,您将可以在项目中同时使用Neo4j和Lucene 4.

So, after this workaround - you will be able to use both: Neo4j and Lucene 4 in your project.

以防万一,这里是具有maven配置的GitHub存储库的链接,用于为Neo4j生成超级JAR":

Just in case, here is link to GitHub repository with maven configuration for generation of "uber JAR" for Neo4j: https://github.com/lagodiuk/neo4j-uber-jar

这篇关于Neo4J 1.9.1的替代IndexProvider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆