所以我的 Solr 文档中有以下多字段(只是一个例子)。
"type": [
"Single",
"Series",
"Other association"
],
"name": [
"Name associated with first type",
"Name associated with second type",
"Name associated with third type"
]
Run Code Online (Sandbox Code Playgroud)
我将能够查询两个字段:
name:"Name associated with third type" AND type:"Series"
Run Code Online (Sandbox Code Playgroud)
但我需要查询 的值name并匹配type同一数组索引中的值。所以上面的例子不应该命中,因为“与第三种类型关联的名称”是第三种,name而“系列”在type.
应该产生命中的查询是这样的,因为两个值都在同一个数组索引中。
name:"Name associated with second type" AND type:"Series"
Run Code Online (Sandbox Code Playgroud)
但这符合一切。我希望这得到了正确的解释。我什至不知道这是否可能。
不,不可能在具有相同索引的两个多值字段之间进行匹配。您将需要获取所有匹配的文档并在客户端处理它们。
但是,如果您始终拥有两者的完整值type,name那么您可以更改您的架构并使其像这样工作。
定义一个名为的新字段type_names,它是一个多值字符串字段。修改索引器以设置该字段中的值,例如
type_names: [Single#Name associated with first type,
Series#Name associated with second type,
Other association#Name associated with third type]
Run Code Online (Sandbox Code Playgroud)
我正在使用#,但您可以使用任何适合您的分隔符字符串。
(如果您想要不区分大小写的匹配并且还想要小写查询值,则可能需要小写索引中的所有内容。)
然后查询该字段,如下所示:
type_names:(Series#Name associated with second type)
Run Code Online (Sandbox Code Playgroud)
如果碰巧您知道(例如)type中的完整值,但只知道一个单词,那么您可以使用正则表达式匹配:namesecond
type_names:/Series#.*second.*/
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1608 次 |
| 最近记录: |