私たちは、検索を実行するためにJavaクライアントAPIおよび構造化されたクエリを使用している2時間MarkLogic構造化照会パフォーマンス比較
でフェッチする必要があり、最大100万件のドキュメントアプリケーションに取り組んでいます。ただし、クエリはまだ遅いです。
コードは以下の通りである:
def fetchPostMessages(dbParam: DbParam): Page = {
val queryManager = dbClient.newQueryManager()
val sqb: StructuredQueryBuilder = queryManager.newStructuredQueryBuilder()
log.info(s "Fetching post messages from database for params: {}", dbParam)
val modifiedQueryDef = dbParam.param.map {
param => {
sqb.and(
sqb.word(sqb.jsonProperty(status), toBeReported),
sqb.word(sqb.jsonProperty(dataCategory), "dataCategory1"),
sqb.range(sqb.jsonProperty(creationDate), marklogicDateFormat.name, Operator.LE, DateUtil.printFpmlDateTime(param.messagesTime)))
}
}.getOrElse(sqb.and(sqb.word(sqb.jsonProperty(status.name), toBeReported.name)))
modifiedQueryDef.setCollections(XmlConstants.ItracMessageTypes.OUTPUT_MESSAGE.name)
modifiedQueryDef.setOptionsName(sortOption)
search(modifiedQueryDef, dbParam.pageNum, dbParam.batchSize)
}
private def search(queryDef: QueryDefinition, startIndex: Int, batchSize: Int): Page = {
val dataList: ListBuffer[Document] = new ListBuffer()
val jsonDocManager = dbClient.newJSONDocumentManager()
jsonDocManager.setMetadataCategories(Metadata.ALL)
jsonDocManager.setPageLength(
if (batchSize < pageLength) batchSize
else pageLength)
val documentPage = jsonDocManager.search(queryDef, startIndex);
dataList.++ = (extractContent(documentPage))
val totalSize = documentPage.getTotalSize
log.info(s "Total documents to be reported : ${totalSize}")
var pageSize = documentPage.getPageSize
while (pageSize < batchSize && pageSize <= totalSize) {
if (batchSize - pageSize < pageSize)
jsonDocManager.setPageLength(batchSize - pageSize)
var newDocPage = jsonDocManager.search(queryDef, pageSize + 1)
dataList.++ = (extractContent(newDocPage))
pageSize = pageSize + newDocPage.getPageSize
}
log.info("Total messages fetched are : {}", dataList.size)
Page(startIndex, totalSize - batchSize, dataList.to[collection.immutable.Seq])
}
ソートオプションは次のとおりデータベースに
<search:options xmlns:search="http://marklogic.com/appservices/search">
<search:sort-order type="xs:string" direction="ascending">
<search:json-property>subdomLvl1</search:json-property>
</search:sort-order>
<search:sort-order type="xs:string" direction="ascending">
<search:json-property>trdId</search:json-property>
</search:sort-order>
<search:sort-order type="xs:string" direction="ascending">
<search:json-property>validStartDate</search:json-property>
</search:sort-order>
<search:sort-order type="xs:string" direction="ascending">
<search:json-property>ver</search:json-property>
</search:sort-order>
<search:sort-order type="xs:string" direction="ascending">
<search:json-property>reportStatus</search:json-property>
</search:sort-order>
</search:options>
インデックスは以下の通りである:範囲索引はのためにある
要素 - ステータス、dataCategory及びcreationDateとすべての並べ替えオプションについて