原因:org.hibernate.search.exception.SearchException:HSEARCH000114:无法加载资源:'synonyms.txt'

Caused by: org.hibernate.search.exception.SearchException: HSEARCH000114: Could not load resource: 'synonyms.txt'

我第一次在 spring 引导中使用 Hibernate 搜索并尝试定义我自己的德语同义词,我正在使用此代码:

@AnalyzerDef(name = "edgeNgram",
            tokenizer = @TokenizerDef(factory = WhitespaceTokenizerFactory.class),
            filters = {
                    @TokenFilterDef(factory = ASCIIFoldingFilterFactory.class), // Replace accented characeters by their simpler counterpart (è => e, etc.)
                    @TokenFilterDef(factory = LowerCaseFilterFactory.class), // Lowercase all characters
                    @TokenFilterDef(
                            factory = EdgeNGramFilterFactory.class, // Generate prefix tokens
                            params = {
                                    @Parameter(name = "minGramSize", value = "2"),
                                    @Parameter(name = "maxGramSize", value = "4")
                            }
                    ),
                    @TokenFilterDef(
                            factory = SynonymFilterFactory.class,
                            params = {
                                    @Parameter(name = "ignoreCase", value = "true"),
                                    @Parameter(name = "expand", value = "true"),
                                    @Parameter(name = "synonyms", value = "synonyms.txt"),
                            })

            })

当我使用“factory = SynonymFilterFactory.class”并定义我的“synonyms.txt”文件时,出现错误:

Caused by: org.hibernate.search.exception.SearchException: HSEARCH000114: Could not load resource: 'synonyms.txt'

我是 spring 引导新手,非常感谢任何帮助! 谢谢

这个:

                                    @Parameter(name = "synonyms", value = "synonyms.txt")

意味着您要求 Hibernate Search 从您的类路径加载名为 synonyms.txt 的文件,并从那里提取同义词列表。

如果类路径的根目录中没有名为 synonyms.txt 的文件,则会出现此异常。

添加文件,一切都应该按顺序恢复。

有关此文件格式的说明,请参阅 org.apache.lucene.analysis.synonym.SolrSynonymParser 的 javadoc。