如何在SOLR中搜索包含[和/或]的字段?

时间:2018-06-05 09:20:55

标签: apache solr

我有SOLR设置。

我想搜索其中包含Tprivate <S> void logIf(Predicate<S> p, S t, PersonId id, String message) { if (p.test(t)) { logMap.put(id, message); } } 的所有文档。

我试过了

[

但它会返回我的数据库中的所有文件。

尝试

]

但它给了

nk_title:"\["

我也试过

nk_title:[*

但是返回空结果。

1 个答案:

答案 0 :(得分:1)

要搜索[,请确保在创建查询时使用\转义它。给定一个title字段定义为string的集合,其中包含三个文档:

{
    "id":"doc1",
    "title":"This is a title",
    "_version_":1602438086510247936
},
{
    "id":"doc2",
    "title":"[This is a title",
    "_version_":1602438093178142720
},
{
    "id":"doc3",
    "title":"This is [a title",
    "_version_":1602438101227012096
}

查询title:[*会将doc2作为点击:

 {"numFound":1,"start":0,"docs":[{
    "id":"doc2",
    "title":"[This is a title",
    "_version_":1602438093178142720}]}

双方的通配符按预期工作(title:*\[*):

"response":{"numFound":2,"start":0,"docs":[
{
    "id":"doc2",
    "title":"[This is a title",
    "_version_":1602438093178142720},
  {
    "id":"doc3",
    "title":"This is [a title",
    "_version_":1602438101227012096}]
}}
相关问题