2017-10-03 1 views
0

Cloudantの新機能ですが、しばらくの間DB2上でSQLで開発されました。私はLuceneクエリエンジンとCloudantインデックスを使用してクエリから結果を返すと思っていますが、予想される3つのフィールドのうち2つだけがデータを返すという問題が発生しています。データを返さないフィールドは配列です。当社のアプリケーションはJavaを実行し、IBMのBluemixとWebSphere Liberty Profileを使用して実行されます。私はcloudant-client-2.8.0.jarとcloudant-HTTP-2.8.0.jarファイルをパッケージ化して、クラウド・データベースにアクセスしました。多くのクエリが動作しているので、接続自体は問題ありません。ここでCloudant Client Search APIを使用してもすべての結果が返されない場合

はCloudant APIにアクセスする私のコードです:私は、Javaを使用しています上記のJavaコードから見ることができるように

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

:ここ

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

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

はthis.getJsonSelectorコードです検索から返されたデータを保持するDocTypeInfo.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; 
    }  

} 

私はセットアップに次のように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}); 
      } 
     } 
     } 
    } 
    }" 
    } 
    } 
} 

DOCTYPEとバージョンのフィールドが移入され、検索を、しかしisPublishedForReportsここでクラスがありますフィールドは常にnullです。返されません。 CloudPadのダッシュボードで、isPublishedForReportsの値が返されていることがわかるインデックスに対してクエリを実行すると、なぜオブジェクトに値が設定されていないのか分かりません。多分私はこれらがどのように構築されるのか誤解していますか?ここで

私はDBを照会し、私は私が望む結果を見ることができるスクリーンショット: enter image description here

が助けてください! -Doug

答えて

1

fieldsプロパティの代わりにresult.rowsの各行からdocsプロパティにアクセスしていると思います。あなたはfields財産とdocプロパティで完全な文書に検索インデックスに定義されたフィールドを見ることができますどのように

{ 
    "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":[...] 
     } 
    } 
    ... 
    ] 
} 

注意:.includeDocs(true)で検索を実行すると次のような結果が表示されます。完全な文書にはisPublishedForReportsは含まれていません。あなたが.includeDocs(false)を設定するだけfieldsプロパティにアクセスすることができます全体のドキュメントを必要としない場合、また

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

あなたが fieldsプロパティにアクセスする必要が isPublishedForReports値を取得します。

+1

あなたの権利と私は答えとしてあなたのマークを付けました。私はそれを変更し、フィールドにアクセスし始めたとき、私は必要なものを得ることができます。ウェルの説明に感謝します。とても有難い。 -Doug M. – Doug

関連する問題