Pymongo-text search-list of phrases

∥☆過路亽.° 提交于 2019-12-12 00:28:55

问题


I have a dictionary of the following structure:

keywords={topic_1:{category_1:['\"phrase_1\"','\"phrase_2\"'],
                   catgeory_2:[''\"phrase_1\"','\"phrase_2\"']},
          topic_2:{category_1:['\"phrase_1\"','\"phrase_2\"','\"phrase_3\"']}}

I have a bunch of documents in mongodb on which I want tag a [category,topic] tag as long as it matches any one of the phrases in the [topic][category].However I need to iterate phrase by phrase as follows(Pymongo):

for topic in keywords:
  for category in keywords[topic]:
      for phrase in keywords[topic][category]:
            docs=db.collection.find({'$text':{'$search':keyword}},{'_id':1})

Instead of this I just want to scan the list of phrases and give me a list of documents that match any one phrase for every [topic][category] list.Is this possible in pymongo?...Is OR-ing of phrases possible?-If so how do I go about it?I tried concatenating the phrases as a single string but that dint work.My actual Mongo collection has a million documents and the dictionary would be very large as well-The performance is brought down if I iterate phrase by phrase

来源:https://stackoverflow.com/questions/32405617/pymongo-text-search-list-of-phrases

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!