我正在尝试对我的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条目,并用其他单词中的小写单词填充它...
$and
仅在1.9.x中可用。
MongoDB 2.6现在可以使用$text
命令结合FTS索引来允许全文搜索。