【问题标题】:CustomAnalyser Lucene Connector GraphDBCustomAnalyser Lucene 连接器 GraphDB
【发布时间】:2018-02-27 14:47:39
【问题描述】:

我在弄清楚如何在 GraphDB 中指定我自己的分析器实现时遇到问题。在阅读了documentation 和其他几个posts 之后,我似乎遇到了.jar 依赖项的问题。

为了构建样板 CustomAnalyzerCustomAnalyzerFactory 类,我必须使用位于 lib/plugins/lucenelucene.jarlucene-core.jar。我的 gradle 构建文件如下所示:

group 'com.example'
version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile fileTree(dir: 'libs/lucene', include: '*.jar')

}

注意:libs/lucene 是我的 gradle 项目中的文件夹,我将 lucene.jarlucene-core.jar 复制到 graphdb 独立服务器分发版的 lib/plugins/lucene

在我编译代码并使用gradle clean jar 创建jar 文件后,我将其复制到lib/plugins/lucene-connector

我重新启动 graph-db,进入连接器并尝试使用 UI 添加一个 lucene-connector。我设法一直到您可以指定分析仪的位置。但是,当我指定 com.example.CustomAnalyzer 时,我收到以下错误消息。

 Caused by: java.lang.NoClassDefFoundError: org/apache/lucene/analysis/ASCIIFoldingFilter

经过一番挖掘,我发现有 2 个 lucene-core.jar 文件。一个在libs/plugins/lucene,另一个在libs/plugins/lucene-connectorlibs/plugins/lucene-connector 中的 lucene-core.jar 没有 ASCIIFoldingFilter 类。

我什至尝试创建一个 fatJar,其中包含一个 jar 中包含的所有依赖项,但是当我这样做时,graphdb 无法加载任何连接器。

不太确定,我哪里出错了,感觉这与我构建和引用 jar 文件的方式有关。


我还尝试从 CustomAnalyzer 中删除 ASCIIFilter,但得到了一组全新的错误:

Caused by: com.ontotext.trree.sdk.BadRequestException: Unable to instantiate analyzer class, only analyzers with a default constructor or a constructor accepting single Version parameter are possible: com.example.CustomAnalyzer
    at com.ontotext.trree.plugin.externalsync.impl.lucene4.CreateAnalyzerUtil.instantiateAnalyzer(CreateAnalyzerUtil.java:70)
    at com.ontotext.trree.plugin.externalsync.impl.lucene4.CreateAnalyzerUtil.createAnalyzerFromClassName(CreateAnalyzerUtil.java:42)
    at com.ontotext.trree.plugin.externalsync.impl.lucene4.Lucene4ExternalStore.open(Lucene4ExternalStore.java:182)
    at com.ontotext.trree.plugin.externalsync.impl.lucene4.Lucene4ExternalStore.initImpl(Lucene4ExternalStore.java:718)
    ... 60 common frames omitted

【问题讨论】:

    标签: graphdb


    【解决方案1】:

    GraphDB 提供两种全文搜索机制。第一个选项是 GraphDB Lucene Connector plugin,这是任何新开发的推荐方法。另一种选择是GraphDB FTS plugin,它使用稍微不同的索引方法。由于索引的性质,它的主要限制是在 RDF 数据更改时缺乏自动同步。

    在您的示例中,您想要扩展 Lucene 连接器,但实际上修改了 FTS 插件的二进制文件。为了简化开发、测试和部署自定义分析器的说明和所有必要步骤,我准备了一个公共项目来尝试:

    https://gitlab.ontotext.com/vassil.momtchev/custom-lucene-analyzer

    【讨论】:

    • 在 Docker 中运行:RUN set -e; \ git clone https://gitlab.ontotext.com/vassil.momtchev/custom-lucene-analyzer.git; \ cd custom-lucene-analyzer; \ sed -i "s/<lucene.version>.*<\/lucene.version>/<lucene.version>7.7.0<\/lucene.version>/g" pom.xml; \ apt update; \ apt install -y maven; ADD CustomAnalyzer.java src/main/java/com/ontotext/graphdb/lucene/CustomAnalyzer.java RUN set -e; \ cd custom-lucene-analyzer; \ mvn install -DskipTests; \ cp target/custom-lucene-analyzer-1.0-SNAPSHOT.jar /opt/graphdb/dist/lib/plugins/lucene-connector;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多