我在cloudant服务器上有一个文件:
{
"_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"
]
}
]
},
}
我为" name"创建了搜索索引。和"价值"在文件中:
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());
}
但它无法在浏览器中获得搜索结果的结果(数据和索引连接也被检查,没关系)。这段代码中的错误是什么?
答案 0 :(得分:3)
使用Lucene Query Parser语法查询搜索索引。尝试使用冒号而不是等号:
List<issue> issues=db.search("searchJson/newSearch")
.limit(10).includeDocs(true)
.query("name:\"web*\"", issue.class);