【发布时间】:2020-04-06 20:19:02
【问题描述】:
如何在 Pymongo 中索引嵌套对象,以便我可以执行全文搜索。例如我有这样的集合对象......
{
"_id":"ObjectId(" "5e8b0fa1c869790699efdb2d" ")",
"xmlfileid": "334355343343223567",
"threads":{
"threads_participants":{
"participant":[
{
"@reference": rits_dbx_1
},
{
"@reference": rits_dbx_2
}
]
},
"thread":{
"namedAnchor":"{' ': 'NORP', 'Ho': 'PERSON', 'Lets': 'PERSON', 'Boris Johnson': 'PERSON', 'Britain': 'GPE'}",
"selectedText":{
"fragment":[
{
"@class":"next_steps",
"#text":"rits_dbx_1 said hello this is a good site."
},
{
"@class":"other",
"#text":"rits_dbx_1 said ho ho."
},
{
"@class":"other",
"#text":"rits_dbx_1 said lets put some meaningful stuff here."
},
]
}
}
}
}
我在我的网站中放置了搜索框,当用户在搜索框中键入 #text 时,我想显示 #text 和 class 以及 xmlfileid
到目前为止,我已经使用以下命令创建了索引。而且我不知道这是获得结果的正确方法,也请帮助查询。
db.xml_collection.createIndex({"threads.thread.selectedText.fragment": "text"})
在我的 python 代码中,我有这个,但什么也没打印
result = collection.find({"$text": {"$search": "ho ho"}})
【问题讨论】: