I am trying to have some form of fulltext search for one of my mongodb collections (a la flowdock). I create a _keywords entry for each document and populate it with lowercased words from the other fields in that document. I then search it like this (prefixed search) ex. searchString = 'car'
found_shots = connection.Shot.find({'_keywords': re.compile('^%s' % searchString.lower())}).limit开发者_JAVA百科(limit).skip(skip)
The problem is when I try to search on multiple words ( ex. 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)
That does not work. any ideas please?
$and
is only available in 1.9.x.
Since you are using 1.8.2 it does not work correctly.
If you upgrade you will get the latest set of commands and you will be able to use the $and command.
MongoDB 2.6 can now allow full text searching using the $text
command combined with a FTS index.
精彩评论