Marklogic Java 客户端 API 条件无效
Marklogic Java Client API criteria not working
我希望获取集合中的所有文档,文档中存在特定术语。
因此,我正在使用以下代码结构:
StringQueryDefinition sqd = queryManager.newStringDefinition();
sqd.setCollections(collectionName);
sqd.setCriteria(searchTerm);
但我得到的结果计数始终为 0,但如果我删除条件,那么我会得到集合中的所有文档。
这种方法有什么问题,请告诉我。
我终于找到了与命名空间约束相关的标签的答案:
//Create options for search:
String options= "<search:options xmlns:search='http://marklogic.com/appservices/search'>"+
"<search:constraint name='constraintname'>"+
"<search:value>"+
"<search:element name='elementname' ns='your-namespace'/>"+
"</search:value>"+
"</search:constraint>"+
"</search:options>";
//Write options to database
QueryOptionsManager optionsManager = client.newServerConfigManager().newQueryOptionsManager();
StringHandle writeHandle = new StringHandle(options);
optionsManager.writeOptions("OPTION_NAME", writeHandle);
//Create StructuredQueryBuilder with the options
StructuredQueryBuilder queryBuilder = queryManager.newStructuredQueryBuilder("OPTIONS_NAME");
//Create StructuredQueryDefinition using the query builder and specify constraint name and value.
StructuredQueryDefinition queryDefinition = queryBuilder.and(queryBuilder.valueConstraint("constraintname", value));
queryDefinition.setCollections(collectionName);
SearchHandle searchHandle = queryManager.search(queryDefinition, new SearchHandle());
我希望获取集合中的所有文档,文档中存在特定术语。 因此,我正在使用以下代码结构:
StringQueryDefinition sqd = queryManager.newStringDefinition();
sqd.setCollections(collectionName);
sqd.setCriteria(searchTerm);
但我得到的结果计数始终为 0,但如果我删除条件,那么我会得到集合中的所有文档。
这种方法有什么问题,请告诉我。
我终于找到了与命名空间约束相关的标签的答案:
//Create options for search:
String options= "<search:options xmlns:search='http://marklogic.com/appservices/search'>"+
"<search:constraint name='constraintname'>"+
"<search:value>"+
"<search:element name='elementname' ns='your-namespace'/>"+
"</search:value>"+
"</search:constraint>"+
"</search:options>";
//Write options to database
QueryOptionsManager optionsManager = client.newServerConfigManager().newQueryOptionsManager();
StringHandle writeHandle = new StringHandle(options);
optionsManager.writeOptions("OPTION_NAME", writeHandle);
//Create StructuredQueryBuilder with the options
StructuredQueryBuilder queryBuilder = queryManager.newStructuredQueryBuilder("OPTIONS_NAME");
//Create StructuredQueryDefinition using the query builder and specify constraint name and value.
StructuredQueryDefinition queryDefinition = queryBuilder.and(queryBuilder.valueConstraint("constraintname", value));
queryDefinition.setCollections(collectionName);
SearchHandle searchHandle = queryManager.search(queryDefinition, new SearchHandle());