1

我正在尝试使用 cloudant 的地理搜索功能。

我创建了一个搜索索引,如下所示:

{
    "_id": "_design/locations2",
    "_rev": "1-ca7f78894c9e6a26539f81322b640b4e",
    "indexes": {
        "find1": "function(doc){if(doc.coord){index('lat', doc.coord[0], {\"store\":\"yes\"});index('lon', doc.coord[1], {\"store\":\"yes\"})}; }"
    }
}  

我有几个文件如下:

{
    "_id": "9b01e808371c049285b1b40d1077c934",
    "_rev": "1-770b0d49ef839713003c5f17f81d3fc1",
    "type": "location",
    "name": "test",
    "description": "description",
    "coord": [ - 31.936722, 115.754979]
}

然后我查询如下:

.cloudant.com/epic_test_db/_design/locations2/_search/find1?q=test

我收到此错误:

{"error":"{case_clause,{<<\"find1\">>,\n              <<\"function(doc){if(doc.coord){index('lat', doc.coord[0], {\\\"store\\\":\\\"yes\\\"});index('lon', doc.coord[1], {\\\"store\\\":\\\"yes\\\"})}; }\">>}}","reason":"[{dreyfus_index,design_doc_to_index,2},\n {dreyfus_rpc,call,5},\n {rexi_server,init_p,3}]"}

知道为什么吗?

4

1 回答 1

1

好的,我找到了答案。我在函数之前的索引定义中错过了索引(doc)

   {
        "_id": "_design/locations2",
        "_rev": "1-ca7f78894c9e6a26539f81322b640b4e",
        "indexes": {
            "find1": {
index: "function(doc){if(doc.coord){index('lat', doc.coord[0], {\"store\":\"yes\"});index('lon', doc.coord[1], {\"store\":\"yes\"})}; }"
        }
    }}  
于 2013-10-07T12:18:38.083 回答