简体   繁体   English

使用Cloudant Client Search API不会返回所有预期结果

[英]Using Cloudant Client Search API Doesn't Return All Results Expected

I am pretty new to Cloudant but have developed in SQL on DB2 for some time. 我对Cloudant相当陌生,但是已经在DB2上的SQL中开发了一段时间。 I am running into an issue where I *think I am using the Lucene query engine and Cloudant indexes to return results from my query, but only two out of three expected fields are returning data. 我遇到一个问题,我*认为我正在使用Lucene查询引擎和Cloudant索引从查询中返回结果,但是三个预期字段中只有两个返回数据。 The field that isn't returning data is an array. 不返回数据的字段是一个数组。 Our application is running Java and executed using IBM's Bluemix and WebSphere Liberty Profile. 我们的应用程序正在运行Java,并使用IBM的Bluemix和WebSphere Liberty Profile执行。 I have packaged the cloudant-client-2.8.0.jar and cloudant-HTTP-2.8.0.jar files to access the cloudant database. 我已经打包了cloudant-client-2.8.0.jar和cloudant-HTTP-2.8.0.jar文件来访问cloudant数据库。 We have many queries that are working so the connection itself is fine. 我们有许多正在运行的查询,因此连接本身很好。

Here is my code that accesses the Cloudant API: 这是我访问Cloudant API的代码:

....
Search searchSaaSData = ServiceManagerSingleton.getInstance().getSaaSCapabilitiesDatabase().search("versioning-ddoc/versioning-indx").includeDocs(true);

SearchResult<DocTypeInfo> result = searchSaaSData.querySearchResult(this.getJsonSelector(deliverableId), DocTypeInfo.class);
....

Here is the this.getJsonSelector code: 这是this.getJsonSelector代码:

private String getVersioningSearch(String deliverableId) {
    String query = "";
    if (deliverableId != null && !deliverableId.isEmpty()) {
        // Search based on deliverableId
        query += "(";
        query += "deliverableId:\"" + deliverableId + "\"" + ")";
    }

    logger.log(Level.INFO, "Search query is: " + query);
    // The query is simple, will look like this: 
    // deliverableId:"0B439290AB5011E6BE74C84817AAB206")

    return query;
}

As you can see from the java code above I am using the java object DocTypeInfo.class to hold the data returned from the search. 从上面的Java代码可以看到,我正在使用Java对象DocTypeInfo.class来保存从搜索返回的数据。 Here is the class: 这是课程:

public class DocTypeInfo {
    private final String docType;
    private final String version;
    private String isPublishedForReports;

    public DocTypeInfo(String docType, String version) {
        this.docType = docType;
        this.version = version;
    }

    /**
     * @return the docType
     */
    private String getDocType() {
        return docType;
    }

    /**
     * @return the version
     */
    private String getVersion() {
        return version;
    }

    /**
     * @return the isPublishedForReports
     */
    public String getIsPublishedForReports() {
        return isPublishedForReports;
    }

    /**
     * @param isPublishedForReports the isPublishedForReports to set
     */
    public void setIsPublishedForReports(String isPublishedForReports) {
        this.isPublishedForReports = isPublishedForReports;
    }       

}

I have setup a design doc and index using the Cloudant dashboard as follows: 我已经使用Cloudant仪表板设置了设计文档和索引,如下所示:

{
"_id": "_design/versioning-ddoc",
"_rev": "22-0e0c0ccfc2b5fe7245352da7e5b1ebd3",
"views": {},
"language": "javascript",
"indexes": {
  "versioning-indx": {
  "analyzer": {
    "name": "perfield",
    "default": "standard",
    "fields": {
      "deliverableId": "whitespace",
      "docType": "standard",
      "version": "standard",
      "isPublishedForReports": "keyword"
    }
  },
  "index": "function (doc) {
               index(\"deliverableId\", doc.deliverableId, {\"store\":true, \"boost\":1.0});
   index(\"docType\", doc.docType, {\"store\":true, \"boost\":1.0});
   index(\"version\", doc.version, {\"store\":true, \"boost\":1.0});
   if (Array.isArray(doc.publishSettings)) {
     for (var i in doc.publishSettings) {
       if (doc.publishSettings[i].options) {
         for (var j in doc.publishSettings[i].options) {
           index(\"isPublishedForReports\", doc.publishSettings[i].options[j].optionId, {\"store\":true, \"boost\":1.0});
           }
         }
       }
     }
   }"
  }
  }
 }

When I execute the search the docType and version fields are populated, however the isPublishedForReports field is ALWAYS null or doesn't return. 当我执行搜索时,将填充docType和version字段,但是isPublishedForReports字段始终为null或不返回。 When I run a query in the Cloudant dashboard against the index I can see the isPublishedForReports value is returned, I don't know why it's not populated in the object? 当我在Cloudant仪表板中针对索引运行查询时,可以看到返回了isPublishedForReports值,我不知道为什么未在对象中填充它? Maybe I am misunderstanding how these get built? 也许我误会了这些是如何建立的?

Here a screenshot where I query the DB and I can see the results I want: 这是我查询数据库的屏幕截图,可以看到想要的结果: 在此处输入图片说明

Please help! 请帮忙! -Doug -Doug

I think you are accessing the docs property from each row in result.rows instead of the fields property. 我认为您是从result.rows中的每一行而不是fields属性访问docs属性。 When you run your search with .includeDocs(true) you will see a result similar to the following: 使用.includeDocs(true)运行搜索时,您将看到类似于以下内容的结果:

{
  "total_rows":3,
  "bookmark":"g1AAA",
  "rows":[
    {
      "id":"263a81ea76528dead3a4185df3676f62",
      "order":[
        1.0,
        0
      ],
      "fields":{
        "docType":"xxx",
        "deliverableId":"yyy",
        "isPublishedForReports":"pu_1_2"
      },
      "doc":{
        "_id":"263a81ea76528dead3a4185df3676f62",
        "_rev":"3-116dd3831c182fb13c12b05a8b0996e4",
        "docType":"xxx",
        "deliverableId":"yyy",
        "publishSettings":[...]
      }
    }
    ...
  ]
} 

Notice how you can see the fields you defined in your search index in the fields property and the full document in the doc property. 注意,如何查看在字段属性中的搜索索引中定义的fields以及在doc属性中的完整文档。 The full document does not include isPublishedForReports . 完整文档不包括isPublishedForReports

To get the isPublishedForReports value you need to access the fields property: 要获取isPublishedForReports值,您需要访问fields属性:

for (SearchResult<DocTypeInfo>.SearchResultRow row : result.getRows()) {
   ...
   row.getFields().getIsPublishedForReports()
   ...
}

Also, if you don't need the whole doc you can set .includeDocs(false) and only access the fields property. 另外,如果不需要整个文档,则可以设置.includeDocs(false) ,仅访问fields属性。

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

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