简体   繁体   English

Neo4j节点索引:如何更改Lucene的默认相似度?

[英]Neo4j node indexing: how to change Lucene default similarity?

I'm using Neo4j (1.9) and lucene core 3.5, through the support offered by the neo4j-lucene-index library. 我正在使用neo4j(1.9)和lucene core 3.5,通过neo4j-lucene-index库提供的支持。 In my code, I create a new node index like that: 在我的代码中,我创建了一个新的节点索引:

    HashMap<String, String> stringMap = new HashMap<String, String>();
    stringMap.put("type", "fulltext");
    stringMap.put(IndexManager.PROVIDER, "lucene");
    stringMap.put("to_lower_case", "false");
    stringMap.put("similarity", MySimilarity.class.getName());
    stringMap.put("analyzer", MyAnalyzer.class.getName());
    simpleIndex = (LuceneIndex<Node>) template.getGraphDatabaseService()
            .index().forNodes("simple-index", stringMap);

and query the node index by means of a multi-field query: 并通过多字段查询查询节点索引:

    Analyzer analyzer = new MyAnalyzer();
    Query query = null;
    try {
        query = MultiFieldQueryParser.parse(Version.LUCENE_35,
                queriesArray, fieldsArray, flagsArray, analyzer);
    } catch (ParseException e) {
        e.printStackTrace();
        return;
    }
    if (query == null)
        return;
    QueryContext qc = new QueryContext(query).sortByScore();
    IndexHits<Node> hits = simpleIndex.query(qc);

How can I change the Similarity implementation, used for sorting by score, to MySimilarity class (which extends the DefaultSimilarity and overrides some of its methods)? 如何将用于按分数排序的相似性实现更改为MySimilarity类(扩展DefaultSimilarity并覆盖其某些方法)? The reported query always uses the DefaultSimilarity and I was not able to find any hook to set the similarity used by the searcher activated during my query. 报告的查询总是使用DefaultSimilarity,我无法找到任何钩子来设置查询期间激活的搜索器使用的相似性。

The fact that the supplied similarity isn't used during queries is a bug and should be fixed. 在查询期间未使用提供的相似性的事实是一个错误,应该修复。 Created https://github.com/neo4j/neo4j/issues/375 to track it. 创建https://github.com/neo4j/neo4j/issues/375来跟踪它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM