有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

未应用java Hibernate搜索从5.11.9迁移到6.0.6 analyzer

在迁移到新版Hibernate Search的过程中,我遇到了一些问题,主要与动态字段和未应用的关联分析器有关

首先,我正在构建分析仪:

private void buildLocalizedAnalyzer(ElasticsearchAnalysisConfigurationContext builder) {
    SupportedLanguage.stream().forEach(
            supportedLanguage ->
            {
                builder.analyzer(supportedLanguage.getDescription() + "Analyzer").custom()
                        .tokenizer(STANDARD)
                        .tokenFilters(LOWERCASE, EDGE_NGRAM_3,
                                supportedLanguage.getDescription() + "Stemmer",
                                supportedLanguage.getDescription() + "Stop"
                        );

                builder.tokenFilter(supportedLanguage.getDescription() + "Stemmer")
                        .type("stemmer").param("language", supportedLanguage.getDescription());

                builder.tokenFilter(supportedLanguage.getDescription() + "Stop")
                        .type("stop").param("stopwords", "_" + supportedLanguage.getDescription() + "_");
            }
    );

}

然后,使用属性活页夹和桥接器,我为所需字段编制索引:

@Override
public void bind(PropertyBindingContext context) {
    context.dependencies().useRootOnly();

    var rootField = context.indexSchemaElement()
            .objectField(context.bridgedElement().name());

    SupportedLanguage.stream().forEach(
            supportedLanguage -> context
                    .indexSchemaElement()
                    .fieldTemplate("localized_analyzer_" + supportedLanguage.name().toLowerCase(), f -> f
                            .asString()
                            .analyzer(supportedLanguage.getDescription() + "Analyzer"))
                    .matchingPathGlob("properties.search_" + supportedLanguage.name().toLowerCase() + "_*"));

     context.bridge(List.class, new PropertyValueBinder.Bridge(rootField.toReference()));
}

在财产桥:

private void indexEnumPropertiesForLocalizedSearch(DocumentElement target,
                                                   PropertyValueEnum propertyValue,
                                                   EnumValue enumValue) {
    var fieldName = PREFIX_SEARCH + DEFAULT + DELIMITER + propertyValue.getProperty().getCode();
    var indexedValue = ((EnumValueString) enumValue).getValue();

    target.addValue(fieldName, indexedValue);

    enumValue.getTranslations().forEach((language, translation) -> {
        var fieldNameTranslated = PREFIX_SEARCH + language.getCode() + DELIMITER + propertyValue.getProperty().getCode();
        var indexedValueTranslated = translation.getValue();

        target.addValue(fieldNameTranslated, indexedValueTranslated);
    });
}

但当我检索术语向量时,没有应用任何分析器,搜索也不起作用:

_termvectors/8?fields=properties.search_en_category

 {
        "_index": "product-000001",
        "_type": "_doc",
        "_id": "8",
        "_version": 1,
        "found": true,
        "took": 0,
        "term_vectors": {
            "properties.search_en_category": {
                "field_statistics": {
                    "sum_doc_freq": 4,
                    "doc_count": 4,
                    "sum_ttf": 4
                },
                "terms": {
                    "Category three": {
                        "term_freq": 1,
                        "tokens": [
                            {
                                "position": 0,
                                "start_offset": 0,
                                "end_offset": 14
                            }
                        ]
                    }
                }
            }
        }
    }

我是否在配置/索引过程中遗漏了什么

提前谢谢


共 (0) 个答案