【发布时间】:2015-12-22 01:06:53
【问题描述】:
我找不到太多关于如何正确定义索引函数的文档,以便我可以对我需要的信息进行全文搜索。
我使用 Alchemy API 将“实体”json 添加到我的文档中。 例如,我有一个包含以下内容的文档:
"_id": "redacted",
"_rev": "redacted",
"session": "20152016",
"entities": [
{
"relevance": "0.797773",
"count": "3",
"type": "Organization",
"text": "California Constitution"
},
{
"relevance": "0.690092",
"count": "1",
"type": "Organization",
"text": "Governors Highway Safety Association"
}
]
我找不到任何代码 sn-ps 显示如何构造一个查看嵌套 json 的搜索索引函数。
我对整个对象的索引似乎不正确。 这是完整的设计文档:
{
"_id": "_design/entities",
"_rev": "redacted",
"views": {},
"language": "javascript",
"indexes": {
"entities": {
"analyzer": "standard",
"index": "function (doc) {\n if (doc.entities.relevance > 0.5){\n index(\"default\", doc.entities.text, {\"store\":\"yes\"});\n }\n\n}"
}
}
}
格式更清晰一点的搜索索引是
function (doc) {
if (doc.entities.relevance > 0.5){
index("default", doc.entities.text, {"store":"yes"});
}
}
按照下面的建议添加 for 循环很有意义。 但是,我仍然无法返回任何结果。 我的查询是 "https://user.cloudant.com/calbills/_design/entities/_search/entities?q=Governors"
服务器响应是: {"total_rows":0,"bookmark":"g2o","rows":[]}
【问题讨论】:
-
您能发布您的查询和服务器响应吗?
-
user.cloudant.com/calbills/_design/entities/_search/…" {"total_rows":0,"bookmark":"g2o","rows":[]}