mongodb全文搜索建议多个单词

问题描述 投票:0回答:2

我正在尝试对我的mongodb集合之一(la flowdock)进行某种形式的全文搜索。我为每个文档创建一个_keywords条目,并使用该文档中其他字段中的小写单词填充它。然后我像这样(前缀搜索)搜索它。 searchString ='car'

found_shots = connection.Shot.find({'_keywords': re.compile('^%s' % searchString.lower())}).limit(limit).skip(skip)

问题是当我尝试搜索多个单词时(例如searchstring = ['car','online']] >>

regex1 = re.compile('^%s' % searchStrings[0].lower())
regex2 = re.compile('^%s' % searchStrings[1].lower())
found_shots = connection.Shot.find({'$and':[{'_keywords':regex1},{'_keywords':regex2}]}).limit(limit).skip(skip)

这不起作用。有什么想法吗?

我正在尝试对我的mongodb集合之一(la flowdock)进行某种形式的全文搜索。我为每个文档创建一个_keywords条目,并用其他单词中的小写单词填充它...

python search mongodb full-text-search
2个回答
1
投票

$and仅在1.9.x中可用。


1
投票

MongoDB 2.6现在可以使用$text命令结合FTS索引来允许全文搜索。

© www.soinside.com 2019 - 2024. All rights reserved.