gpt4 book ai didi

java - 如何让 MongoDB 将 "ł"视为同义词 "l"?

转载 作者:可可西里 更新时间:2023-11-01 10:42:03 26 4
gpt4 key购买 nike

我在 MongoDB 中遇到字符修饰问题。例如,我有单词:"śliwka",当我使用完整搜索时,MongoDB 会自动将该单词转换为 "sliwka",但如果我想搜索该单词"łukasz" MongoDB 没有将其转换为 "lukasz"

如何让 MongoDB 将 łl 视为同一个字符?

最佳答案

在 MongoDB 中有一个创建同义词的库:

https://github.com/seelio/mongoose-synonyms

用法

After defining your schema, load the plugin with the dictionary to use for each field:

var mongooseSynonyms = require('mongoose-synonyms');
var MySchema = new mongoose.Schema({ ... });
MySchema.plugin(mongooseSynonyms, {
dictionary: 'nicknames',
fields: ['firstName', '$text.$search']
});

The keyOnly makes sure that each term will be replaced by the dictionary key only, thus avoiding all possible synonyms. For example, the for the following dictionary entry:

dictionary["łukasz"] = ["lukasz"];

dictionary["ł"] = ["l"];

关于java - 如何让 MongoDB 将 "ł"视为同义词 "l"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38802889/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com