apache - 如何在 SOLR 中搜索包含 [ 和/或 ] 的字段?
问题描述
我有 SOLR 设置。
我想搜索所有包含[
或]
其中的文档。
我努力了
nk_title:"\["
但它会返回我数据库中的所有文档。
试过了
nk_title:[*
但它给了
"error": {
"msg": "org.apache.solr.search.SyntaxError: Cannot parse 'nk_source:156 AND nk_title:[*': Encountered \"<EOF>\" at line 1, column 29.\nWas expecting one of:\n \"TO\" ...\n <RANGE_QUOTED> ...\n <RANGE_GOOP> ...\n ",
"code": 400
}
我也试过
nk_title:\[*
nk_title:*[*
但返回空结果。
解决方案
要搜索[
,只需确保\
在创建查询时将其转义即可。给定一个集合,其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}]
}}
推荐阅读
- android - ScrollView 在片段中不起作用
- php - 最后一个值没有存储在codeigniter会话中的数组中
- oracle - 如何将 oracle 日期格式转换为 IST 格式?
- c# - 在 Visual Studio 代码中构建现有代码
- r - 与上一时期相比,显示增加/减少值的变异列
- python - 使用 apt_pkg 以编程方式安装 debian 软件包时出错
- json - 如何将原始字典转换为 JSON 字符串?
- javascript - 如何使用 javascript 和 jquery 在 html 中动态创建 div 卡?
- elixir - 如何查看一个文件是从另一个文件导入还是作为入口点运行?
- networking - 当客户端尝试连接到接入点并且主路由器中有可用位置时重定向客户端