MarkLogic 搜索和检索特定字段
MarkLogic search and retrieve specific fields
我是 MarkLogic(和 noSQL)的新手,目前正在尝试学习 Java API 客户端。我的搜索问题 returns 返回搜索结果片段/匹配项,搜索结果是否可以在文档中包含 特定字段?
例如,给定此文档:
{"id":"1", "type":"classified", "description": "This is a classified type."}
我用这个搜索:
QueryManager queryMgr = client.newQueryManager();
StringQueryDefinition query = queryMgr.newStringDefinition();
query.setCriteria("classified");
queryMgr.search(query, resultsHandle);
如何将 JSON 文档的 3 个定义字段(id、类型、描述)作为搜索结果的一部分 - 这样我就可以在我的 UI table 中显示它们?
我是否需要通过 URI 加载文档来再次访问数据库(因此,如果我有 1000 条记录,这意味着再次访问数据库 1000 次)?
您可以通过多种方式在搜索结果中检索特定字段。您可以使用 Pojo Data Binding Interface. You could read multiple documents matching a query which brings back the entirety of each document which you can then get as a pojo or String or any other handle. Or you can use the same API you're using above but add search options to allow you to extract a portion of a matching document.
如果您要返回数千个匹配项,您可能不会向最终用户显示所有这些片段,因此您可能应该 disable snippets 使用类似
的方法
<transform-results apply="empty-snippet" />
在您的选项中。
我是 MarkLogic(和 noSQL)的新手,目前正在尝试学习 Java API 客户端。我的搜索问题 returns 返回搜索结果片段/匹配项,搜索结果是否可以在文档中包含 特定字段?
例如,给定此文档:
{"id":"1", "type":"classified", "description": "This is a classified type."}
我用这个搜索:
QueryManager queryMgr = client.newQueryManager();
StringQueryDefinition query = queryMgr.newStringDefinition();
query.setCriteria("classified");
queryMgr.search(query, resultsHandle);
如何将 JSON 文档的 3 个定义字段(id、类型、描述)作为搜索结果的一部分 - 这样我就可以在我的 UI table 中显示它们?
我是否需要通过 URI 加载文档来再次访问数据库(因此,如果我有 1000 条记录,这意味着再次访问数据库 1000 次)?
您可以通过多种方式在搜索结果中检索特定字段。您可以使用 Pojo Data Binding Interface. You could read multiple documents matching a query which brings back the entirety of each document which you can then get as a pojo or String or any other handle. Or you can use the same API you're using above but add search options to allow you to extract a portion of a matching document.
如果您要返回数千个匹配项,您可能不会向最终用户显示所有这些片段,因此您可能应该 disable snippets 使用类似
的方法<transform-results apply="empty-snippet" />
在您的选项中。