全文索引搜索功能在cloudant中无效。
文件1:
{
"_id": "527c8d9327c6f27f17df0d2e17000530",
"_rev": "9-4a61c6dac8d03a7d55696c3dde6a4f50",
"employee_ID": "SCI130202",
"proj_role": "Team Member",
"work_total_experience": "4",
}
文件2:
{
"_id": "527c8d9327c6f27f17df0d2e17000531",
"_rev": "9-4a61c6dac8d03a7d55696c3dd46a4f50",
"employee_ID": "SCI130201",
"proj_role": "developer",
"work_total_experience": "2",
}
索引功能:
{
"_id": "_design/search_emp",
"_rev": "3-4562324d684a2f13d2a1f6f570736e7e",
"views": {},
"language": "javascript",
"indexes": {
"by_employee": {
"analyzer": "standard",
"index": "function(doc){index(doc.proj_role,{'field':'project_role'})index(doc.work_total_experience,{'field':'work_experience'})}"
}}}
如果我传递的网址如:https://{username}.cloudant.com/databasename/_design/search_emp/_search/by_employee?q=project_role:developer & work_experience:2
这仅适用于一种情况,但我需要获得具有2年经验详情的确切输出开发人员。
答案 0 :(得分:1)
所以这里有两个问题,一个是你如何定义索引,一个是你如何查询它。
你正在调用index(doc.proj_role,{'field':'project_role'});
,但我不确定这是正确的语法;我相信你想:index("project_role", doc.proj_role);
两个条件之间的&
应为AND
:q=project_role:developer AND work_experience:2
希望有所帮助。
答案 1 :(得分:0)
这对我有用......
这是我的设计文档:
{
"doc": {
"_id": "_design/search_emp",
"_rev": "17-e7f119c21ca21cc6ac44c5a967cd5550",
"indexes": {
"by_employee": {
"analyzer": "standard",
"index": "function(doc) {\n index('project_role', doc.proj_role, {});\n index('work_experience', doc.work_total_experience, {});\n}"
}
},
"language": "javascript",
"views": {}
},
"id": "_design/search_emp",
"key": "_design/search_emp",
"value": {
"rev": "17-e7f119c21ca21cc6ac44c5a967cd5550"
}
}
网址:
https://username.cloudant.com/databasename/_design/search_emp/_search/by_employee?include_docs=true&q=work_experience:%222%22%20AND%20project_role:developer
注意:我必须在经验值周围加上双引号。 work_experience:"2"
为我工作,但work_experience:2
无效。
回应:
{
"bookmark": "g2wAAAABaANkABxkYmNvcmVAZGIyLm1lYWQuY2xvdWRhbnQubmV0bAAAAAJiQAAAAGJ_____amgCRj_bxezgAAAAYQBq",
"rows": [
{
"doc": {
"_id": "90958a20a020a7483d3311a156fcf571",
"_rev": "1-795df1c239d3d029eaa6d8c45ef70a8c",
"employee_ID": "SCI130201",
"proj_role": "developer",
"work_total_experience": "2"
},
"fields": {},
"id": "90958a20a020a7483d3311a156fcf571",
"order": [
0.4339554011821747,
0
]
}
],
"total_rows": 1
}