变音符号不区分大小写的搜索环回 [英] Diacritic Case-Insensitive search Loopback
问题描述
是否可以使用不区分大小写的选项在Loopback + MongoDB上查询结果?
Is there any way to query results on Loopback+MongoDB with Diacritic-Case-Insensitive options?
例如,如果我要搜索查询olimpic
,并且数据库包含类似以下内容的单词:
For example, If I want to search for the query olimpic
, and the database contains words like:
Olímpic
olimpic
Olimpic
然后,将以上所有内容作为结果返回. 我尝试了下面列出的多个查询以及其他组合,但到目前为止没有任何效果.
Then, all of the above should be returned as results. I have tried with multiple queries listed below and other combinations, but nothing has worked so far.
{"where":{"name.text":{"like":"olimpic","options":"i"}}}
{"where":{"name.text":{"like":"/^olimpic$/i","options":"i"}}}
{"where":{"name.text":{"like":"/.*olimpic.*/i"}}}
{"where":{"name.text":{"regexp":"/.*olimpic.*/i"}}}
有什么主意吗?
提前谢谢!
推荐答案
文本索引(自MongoDB 3.1.7版开始).有关详细信息,请参见 SERVER-19557 .早期版本无法处理变音符号.
What you want ought to be possible with text indices as of version 3.1.7 of MongoDB. Please see SERVER-19557 for details. Earlier versions can not deal with diacritics.
设置文本索引非常容易:只需在要搜索的所有字段上创建索引-每个集合只能有一个文本索引:
Setting up a text index is rather easy: simply create an index on all fields you want to be searched – there can be only one text index per collection:
db.yourCollection.createIndex(
{"name.text":"text","foo":"text"},
{"default_language":"french"}
)
现在,要搜索索引,只需执行以下操作:
Now, to search your index, you simply do the following:
db.yourCollection.find(
{ $text: {$search:"Olimpic"} }
)
应该可以给您预期的结果.
which should give you the expected results.
hth
这篇关于变音符号不区分大小写的搜索环回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!