首页 文章

如何在 GraphDB 全文搜索中创建自定义 AnalyzerFactory?

提问于
浏览
0

(使用 GraphDB 8.1 免费)。 http://graphdb.ontotext.com/documentation/free/full-text-search.html表示我可以通过实现接口com.ontotext.trree.plugin.lucene.AnalyzerFactory,使用luc:analyzer param 为 GraphDB full-text 搜索启用自定义 AnalyzerFactory。但是我无法在任何地方找到这个界面。它不在 jar graphdb-free-runtime-8.1.0.jar 中。

我在http://ontotext.com/products/graphdb/editions/#feature-comparison-table检查了特征矩阵,看来这个功能“连接器 Lucene”可用于免费版的 GraphDB。

com.ontotext.trree.plugin.lucene.AnalyzerFactory接口位于哪个 jar 中?我需要在项目中导入什么才能实现此接口?

GraphDB 中是否包含 pre-existing AnalyzerFactories 以使用 Lucene 其他分析仪? (我有兴趣使用 FrenchAnalyzer)。

谢谢 !

1 回答

  • 1

    GraphDB 提供了两种不同的 Lucene-based 插件。

    我鼓励您使用 Lucene 连接器,除非您没有 RDF 分子的特殊情况。下面是一个简单的示例,如何使用法语分析器配置连接器,并为urn:MyClass类型的资源索引rdfs:label谓词的所有值。选择一个存储库,并从 SPARQL 查询视图执行:

    PREFIX :<http://www.ontotext.com/connectors/lucene#>
      PREFIX inst:<http://www.ontotext.com/connectors/lucene/instance#>
      INSERT DATA {
        inst:labelFR-copy :createConnector '''
      {
        "fields": [
          {
            "indexed": true,
            "stored": true,
            "analyzed": true,
            "multivalued": true,
            "fieldName": "label",
            "propertyChain": [
              "http://www.w3.org/2000/01/rdf-schema#label"
            ],
            "facet": true
          }
        ],
        "types": [
          "urn:MyClass"
        ],
        "stripMarkup": false,
        "analyzer": "org.apache.lucene.analysis.fr.FrenchAnalyzer"
      }
      ''' .
      }
    

    然后从导入>文本区域手动添加一些示例测试数据:

    <urn:instance:test>  <http://www.w3.org/2000/01/rdf-schema#label> "C'est une example".
    <urn:instance:test> a <urn:MyClass>.
    

    提交事务后,Connector 将更新 Lucene 索引。现在您可以运行以下搜索查询:

    PREFIX : <http://www.ontotext.com/connectors/lucene#>
    PREFIX inst: <http://www.ontotext.com/connectors/lucene/instance#>
    SELECT ?entity ?snippetField ?snippetText {
        ?search a inst:labelFR ;
                :query "label:*" ;
                :entities ?entity .
        ?entity :snippets _:s .
        _:s :snippetField ?snippetField ;
            :snippetText ?snippetText .
    }
    

    要创建自定义分析器,请按照文档中的说明进行操作并扩展org.apache.lucene.analysis.Analyzer类。将自定义分析器 JAR 放在lib/plugins/lucene-connector/路径中。

相关问题