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

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

问题描述

我在我的应用程序中使用 Lucene 4 并且不想改变它.我正在尝试集成将 Lucene 3.5 捆绑为 IndexProvider 实现的 Neo4J,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 阴影插件

所以,我在Maven Shade Plugin<的帮助下解决了问题/a>.

So, I have solved issue with help of Maven Shade Plugin.

Maven Shade Plugin 提供了将所有依赖项合并到单个fat"JAR(也称为uber JAR")的能力.

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

因此,您可以生成uber 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 Plugin 提供了在生成uber JAR"期间重定位类的能力:http://maven.apache.org/plugins/maven-shade-plugin/examples/class-relocation.html

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 Plugin 会将类从指定的包及其子包移动到其他包,并会重写受影响的字节码.

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 编写uber JAR"期间 - 您可以配置 Shade Plugin 将 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.*

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

(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>

描述的配置 - 提供为 Neo4j 生成uber JAR"的能力,使用 Lucene 3 的重命名包(只需执行 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 生成uber JAR":https://github.com/lagodiuk/neo4j-uber-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天全站免登陆