简体   繁体   English

通过Cloudant-Client API访问搜索索引

[英]Access search index by cloudant-client api

I have a document in cloudant server as: 我在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"
        ]
      }
    ]
  },
}

I created search index for "name" and "value" in documents as: 我在文档中为“名称”和“值”创建搜索索引为:

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

and I have successfully performanced the query ( https://xxx.cloudant.com/issuedb/_design/searchJson/_search/newSearch?limite=10&include_docs=true&q=name:"web*" )in browser to get the result. 并且我已经在浏览器中成功执行了查询( https://xxx.cloudant.com/issuedb/_design/searchJson/_search/newSearch?limite=10&include_docs=true&q=name:"web*" )以获取结果。 Moreover, I want to get the results by cloudant-client api. 此外,我想通过cloudant-client api获得结果。 The below is my code 下面是我的代码

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

But it can not get the result as search query in browser (Data and index connection are also checked, it is fine). 但它无法在浏览器中作为搜索查询获得结果(也检查了数据和索引连接,很好)。 What is the mistake in this code. 这段代码有什么错误。

Search indexes are queried using Lucene Query Parser Syntax. 使用Lucene查询解析器语法查询搜索索引。 try using a colon instead of the equal sign: 尝试使用冒号而不是等号:

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

More Info: 更多信息:
Cloudant Search 云量搜索
Lucene Query Parser Syntax Lucene查询解析器语法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM