2016-04-14 43 views
0

我在cloudant服務器的文件爲:訪問搜索按cloudant客戶端API指數

{ 
    "_id": "web", 
    "_rev": "11-b1d0e315272a87c2549df4004d836049", 
    "min_weight": 40, 
    "max_weight": 65, 
    "min_length": 1, 
    "max_length": 2.2, 
    "attributeCollection": { 
    "attributeArray": [ 
     { 
     "updateable": false, 
     "lookup": "issuetype", 
     "issueAttributeDefinitionId": 13, 
     "attributeType": 1, 
     "name": "web issue", 
     "value": [ 
      "Improper Neutralization of Input During Web Page Generation" 
     ] 
     } 
    ] 
    }, 
} 

我創建的搜索索引「名稱」,並在文件的「價值」:

function (doc) { 
    if (doc.attributeCollection && doc.attributeCollection.attributeArray) { 
     for (var i=0; i<doc.attributeCollection.attributeArray.length; i++) { 
     if (doc.attributeCollection.attributeArray[i].name) { 
      index("name", doc.attributeCollection.attributeArray[i].name, { store : true }); 
     } 
      if (doc.attributeCollection.attributeArray[i].value) { 
      for (var j=0; j<doc.attributeCollection.attributeArray[i].value.length; j++) { 
       index("value", doc.attributeCollection.attributeArray[i].value[j], { store : true }); 
      } 
     } 
     } 
    } 
} 

並且我已經在瀏覽器中成功地執行了查詢(https://xxx.cloudant.com/issuedb/_design/searchJson/_search/newSearch?limite=10&include_docs=true&q=name:"web*")以獲得結果。而且,我想通過cloudant-client API獲得結果。以下是我的代碼

CloudantClient client=new CloudantClient("xxx", "xxx", "xxx"); 
System.out.println("Connection successful! "+client.getBaseUri()); 
Database db=client.database("issuedb", true); 
System.out.println("Datase available - "+db.getDBUri()); 

List<issue> issues=db.search("searchJson/newSearch") 
.limit(10).includeDocs(true) 
.query("name=\"web*\"", issue.class); 

for (int i = 0; i < issues.size(); i++) { 
    issue iss=issues.get(i); 
    System.out.println(iss.getId()); 
    System.out.println(iss.getName()); 
    System.out.println(iss.getValue()); 
} 

但它不能得到結果在瀏覽器搜索查詢(數據和索引的連接也被選中,這是罰款)。這段代碼中的錯誤是什麼?

回答

3

使用Lucene Query Parser語法查詢搜索索引。嘗試使用,而不是等號冒號:

List<issue> issues=db.search("searchJson/newSearch") 
.limit(10).includeDocs(true) 
.query("name:\"web*\"", issue.class); 

更多信息:
Cloudant Search
Lucene Query Parser Syntax