2016-04-14 6 views
0

ich ein Dokument in cloudant Server als:Zugriff Suchindex von cloudant-client 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" 
     ] 
     } 
    ] 
    }, 
} 

I Suchindex für "name" erstellt und "Wert" in Dokumenten wie:

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 }); 
      } 
     } 
     } 
    } 
} 

und ich habe erfolgreich die Abfrage (https://xxx.cloudant.com/issuedb/_design/searchJson/_search/newSearch?limite=10&include_docs=true&q=name:"web*") im Browser durchgeführt, um das Ergebnis zu erhalten. Außerdem möchte ich die Ergebnisse von Cloudant-Client API erhalten. Die unter meinem Code ist

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()); 
} 

Aber es kann nicht das Ergebnis als Suchbegriff in Browser erhalten (Daten und Index-Verbindung auch geprüft, es ist in Ordnung). Was ist der Fehler in diesem Code?

Antwort

3

Suchindizes werden mit Lucene Query Parser Syntax abgefragt. versuchen, einen Doppelpunkt statt des Gleichheitszeichen:

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

Mehr Info:
Cloudant Search
Lucene Query Parser Syntax