【问题标题】:CLoudant geo search functionCLoudant地理搜索功能
【发布时间】:2013-10-12 23:31:24
【问题描述】:

我正在尝试使用 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}]"}

知道为什么吗?

【问题讨论】:

    标签: indexing cloudant


    【解决方案1】:

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

       {
            "_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\"})}; }"
            }
        }}  
    

    【讨论】:

      猜你喜欢
      • 2015-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多