【发布时间】:2018-01-23 04:19:12
【问题描述】:
我的目标是尝试在 Marklogic 上使用 Java 进行通配符搜索。
我目前在 Marklogic 的工作。
/articles/1.json
1.json:
[{
"title":"hello%20world1",
"content":"article content etc..."
}]
/articles/2.json
2.json:
[{
"title":"hello world 2",
"content":"article content etc..."
}]
/articles/3.json
3.json:
[{
"title":"hello world 3",
"content":"article content etc..."
}]
我的 Java API
第一选择
StructuredQueryBuilder qb = new StructuredQueryBuilder();
String[] queryOptions = {"case-insensitive","wildcarded"};
QueryDefinition queryDef = qb.value(qb.jsonProperty("title"),
FragmentScope.DOCUMENTS,queryOptions
,100.0,"*"+keyword+"*");
// if possible, can someone explain what does that "weight" property
// which I set as 100.0 does?
SearchHandle resultsHandle = new SearchHandle();
queryManager.setPageLength(PAGE_SIZE_MAX);
queryManager.search(queryDef, resultsHandle,0);
我尝试使用“world1”一词进行搜索
所有文章都被退回。那不是我想要的。正确来说,只有 article1 应该被退回。逻辑似乎正确,但查询似乎不起作用。
所以我尝试了另一种方法来测试是选项问题还是我的数据问题。
第二种选择
StructuredQueryBuilder qb = new StructuredQueryBuilder();
QueryDefinition queryDef = qb.word(qb.jsonProperty("title"),keyword);
// correct me if i'm wrong, this line will mean it will take the title
// as long as the title contains the keyword right?
SearchHandle resultsHandle = new SearchHandle();
queryManager.setPageLength(PAGE_SIZE_MAX);
queryManager.search(queryDef, resultsHandle,0);
我使用以下术语进行了测试:
- “hello”,所有结果都按预期返回。
- “worl”,期望返回所有结果,但没有返回
- “world”,期望返回所有结果,但只返回第 2 条和第 3 条
因此,总而言之,如上所述,我的目标是进行通配符搜索。理想的结果是:
- “wor”,返回所有结果。
另外,有什么方法可以在搜索过程中忽略那个“%20”吗?
【问题讨论】:
标签: java json search wildcard marklogic