CLoudant地理搜索功能

时间:2013-10-06 08:59:02

标签: indexing cloudant

我正在尝试使用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 =测试

我收到此错误:

{"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}]"}

知道为什么吗?

TA

1 个答案:

答案 0 :(得分: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\"})}; }"
        }
    }}