我有JSON對象,用於作業具有按鍵調用技能並且是技能列表的JSON對象。例如使用django和mongoengine執行正則表達式查詢
{
"_id" : ObjectId("552a42cd03462b0728feb180"),
"did" : "JB77FW6885MCCRGG30T",
"attributes" : {
"EducationRequired" : "Bachelor's Degree",
"ExperienceRequired" : "At least 3 year(s)",
"ExternalApplication" : "True",
"City" : "Houston",
"Company" : "IBM",
"DegreeRequired" : "4 Year Degree",
"Skills" : {
"Skill" : [
"apache hadoop",
"etl",
"geographic information system",
"cloud computing",
"mongodb",
"nosql",
"linux",
"spark (programming language)",
"java (programming language)",
"python (programming language)",
"sql",
"machine learning",
"data management",
"data integration"
]
}
}
}
{
"_id" : ObjectId("552a42cd03462b0728feb180"),
"did" : "JB77FW6885MCCRGG30T",
"attributes" : {
"EducationRequired" : "Bachelor's Degree",
"ExperienceRequired" : "At least 5 year(s)",
"ExternalApplication" : "True",
"City" : "Boston",
"Company" : "Microsoft",
"DegreeRequired" : "4 Year Degree",
"Skills" : {
"Skill" : [
"java (programming language)",
"python (programming language)",
"sql",
"machine learning",
"data management",
"data integration"
]
}
}
}
我想有「SQL」或'Java的
的工作,我有以下呼叫
skills = ['java','sql']
jobs = Job.objects(__raw__={'attributes.Skills.Skill' : {'$in' : skills}})
這樣做的問題是,它不返回具有'java'的作業,因爲在數據庫中,技能列表具有'java(編程語言)'而不僅僅是'java'。爲了解決這個問題,我需要在查詢中添加一個正則表達式。所以我嘗試了以下但他們都沒有工作:
Job.objects(__raw__={'attributes.Skills.Skill' : {'$in' : ['$/.*java.*/']}}) #ignoring sql for now
Job.objects(__raw__={'attributes.Skills.Skill' : {'$in' : ['sql',re.compile('$/.*java.*/', re.IGNORECASE)]}})
Job.objects(__raw__={'attributes.Skills.Skill' : {'$in' : ['sql',re.compile('/.*java.*/', re.IGNORECASE)]}})
任何想法,我應該做什麼?
爲什麼不直接看'java(編程語言)'?像'skills = ['java(編程語言)','sql']'? – BorrajaX
,因爲java平臺等數據中還有其他java(xxxxxx)實例。通常候選人都有Java技能,但職業生涯API有java(編程語言)等等。 – Amer