Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >运行在多个字段上的eDisMax解析器问题

运行在多个字段上的eDisMax解析器问题
EN

Stack Overflow用户
提问于 2022-07-14 03:59:05
回答 1查看 135关注 0票数 2

环境==> solr - solr-8.9.0,java版本"11.0.12“2021-07-20 LTS

下面的.csv文件是在solr中索引的

代码语言:javascript
运行
AI代码解释
复制
books_id,cat,name,price,inStock,author,series_t,sequence_i,genre_s
0553573403,book,Game Thrones Clash,7.99,true,George R.R. Martin,"A Song of Ice and Fire",1,fantasy
0553573404,book,Game Thrones,7.99,true,George Martin,"A Song of Ice and Fire",1,fantasy
0553573405,book,Game Thrones,7.99,true,George,"A Song of Ice and Fire",1,fantasy

我想找一本名叫“游戏权力冲突”(与mm=75%)和作者乔治·R·马丁(mm=70%)的书。

现在,我想在只有“名称”字段的最小匹配值中搜索图书名。此外,还需要以不同的mm值在作者中搜索作者。

字段类型: text_general配置为字段:'name','author‘,多值为false。

查询将运行输入字段“name”(mm=75%),其值为“游戏权力冲突”,而作者(mm=70%)的值为“GeorgeR.R.Martin”。

显示结果的标准有三个,只有符合下列所有三个标准的结果才能显示出来:

  1. 如果在“name”字段中有至少75%的标记是模糊匹配,那么它应该会导致输出;如果在“author”字段中有至少70%的标记是模糊匹配,则会导致输出。如果字段'inStock‘有’true‘,则会导致

输出应包含以下结果。

代码语言:javascript
运行
AI代码解释
复制
0553573403 (name - 75% matched as well author 70% matched)
0553573404 (name - 75% matched as well author 70% matched)

以下books_id将不包含在输出中。

代码语言:javascript
运行
AI代码解释
复制
0553573405 (name - 75% matched but author not 70% matched)

我知道扩展的DisMax包含查询参数‘mm’(最小应该匹配)和模糊搜索功能,但是下面的查询给出了所有三个结果。

代码语言:javascript
运行
AI代码解释
复制
curl -G http://$solrIp:8983/solr/testCore2/select --data-urlencode "q=(name:'Game~' OR name:'Thrones~' OR name:'Clash~')" --data-urlencode "defType=edismax" --data-urlencode "mm=75%" --data-urlencode "q=(author:'George~' OR author:'R.R.~' OR author:'Martin~')" --data-urlencode "defType=edismax" --data-urlencode "mm=70%" --data-urlencode "sort=books_id asc"
{
  "responseHeader":{
    "status":0,
    "QTime":3,
    "params":{
      "mm":["75%",
        "70%"],
      "q":["(name:'Game~' OR name:'Thrones~' OR name:'Clash~')",
        "(author:'George~' AND author:'R.R.~' AND author:'Martin~')"],
      "defType":["edismax",
        "edismax"],
      "sort":"books_id asc"}},
  "response":{"numFound":3,"start":0,"numFoundExact":true,"docs":[
      {
        "books_id":[553573403],
        "cat":["book"],
        "name":"Game Thrones Clash",
        "price":[7.99],
        "inStock":[true],
        "author":"George R.R. Martin",
        "series_t":"A Song of Ice and Fire",
        "sequence_i":1,
        "genre_s":"fantasy",
        "id":"3de00ecb-fbaf-479b-bfde-6af7dd63c60f",
        "_version_":1738326424041816064},
      {
        "books_id":[553573404],
        "cat":["book"],
        "name":"Game Thrones",
        "price":[7.99],
        "inStock":[true],
        "author":"George Martin",
        "series_t":"A Song of Ice and Fire",
        "sequence_i":1,
        "genre_s":"fantasy",
        "id":"a036a400-4f54-4c90-a52e-888349ecb1da",
        "_version_":1738326424107876352},
      {
        "books_id":[553573405],
        "cat":["book"],
        "name":"Game Thrones",
        "price":[7.99],
        "inStock":[true],
        "author":"George",
        "series_t":"A Song of Ice and Fire",
        "sequence_i":1,
        "genre_s":"fantasy",
        "id":"36360825-1164-4cb6-bf48-ebeaaff0ef10",
        "_version_":1738326424111022080}]
  }}

有人能帮我写edismax查询或其他方式吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-22 18:07:16

嵌套查询可以为查询的不同部分指定不同的查询参数。

代码语言:javascript
运行
AI代码解释
复制
+_query_:"{!edismax mm=75% df=name} Game~ Thrones~ Clash~"
+_query_:"{!edismax mm=70% df=author} George~ R.R.~ Martin~"
+inStock:true

  • 嵌套查询是使用_query_:作为前缀指定的(参见引用1、2)。
  • Local 3 {! ... }...通过前缀查询字符串指定查询解析器及其参数。{!edismax}...
  • minimum
  • 查询类型4 eDisMax 5:{!type=edismax}...或仅为应项匹配(mm) 6:{!mm=75%}...
    • default字段(df) 7:{!df=author}...

可以通过以下任一项指定需要这两个子查询的

  • +query1 +query2
  • query1 AND query2

  • 换行是为了清晰起见,所有行都在一个查询参数(q=)内。parsed.)

(如果存在多个q=参数,则添加debugQuery=true参数显示只有一个是q=参数)。

测试

使用本地Solr 9在架构设计器页面的云模式中再现测试的步骤:

solr-9.0.0/bin/solr start -e cloud

  • answer命令行:直到返回到web浏览器中的命令提示符

  • On the Schema Designer选项卡,

  • 单击New

H 158命名新模式:eDisMaxTest1

  • Copy:_default

  • click Add SchemaH 265H 166示例文档E 268,过去的csv数据并单击分析Documents.

  • Under <代码>E 171模式编辑器,选择字段、作者和名称以及将类型更改为text_general.

  • disabled多值checkbox.

  • clicked Update

  • 以查找URL:从模式设计器页面、打开的浏览器F12调试器、

  • 启用网络选项卡、

  • 执行查询:在查询测试器E 287中,单击RunQuery

  • copy路径http://localhost:8983/api/schema-designer/query

  • copy参数

  • copy>d93和d94(值可能不同)。H 295F 296

请求:一个查询字符串

bash: (\在换行符继续行之前,省略‘.’)

代码语言:javascript
运行
AI代码解释
复制
curl --silent --get localhost:8983/api/schema-designer/query \
  --data-urlencode "_=1658489222229" \
  --data-urlencode "configSet=eDisMaxTest1" \
  --data-urlencode 'q= +_query_:"{!edismax mm=75% df=name} Game~ Thrones~ Clash~" 
                       +_query_:"{!edismax mm=70% df=author} George~ R.R.~ Martin~"
                       +inStock:true' \
  --data-urlencode "sort=books_id asc"

cmd: (在换行符之前,即使在“.”内)

代码语言:javascript
运行
AI代码解释
复制
curl --silent --get localhost:8983/api/schema-designer/query ^
  --data-urlencode "_=1658489222229" ^
  --data-urlencode "configSet=eDisMaxTest1" ^
  --data-urlencode 'q= +_query_:"{!edismax mm=75% df=name} Game~ Thrones~ Clash~" ^
                       +_query_:"{!edismax mm=70% df=author} George~ R.R.~ Martin~" ^
                       +inStock:true' ^
  --data-urlencode "sort=books_id asc"

替代请求:使用嵌套查询参数v=$param引用包含子查询项的其他请求参数。

bash: (\在换行符继续行之前,省略‘.’)

代码语言:javascript
运行
AI代码解释
复制
curl --silent --get localhost:8983/api/schema-designer/query \
  --data-urlencode "_=1658489222229" \
  --data-urlencode "configSet=eDisMaxTest1" \
  --data-urlencode 'q= +_query_:"{!edismax mm=75% df=name v=$qname}"
                       +_query_:"{!edismax mm=70% df=author v=$qauthor}"
                       +inStock:true' \
  --data-urlencode "qname= Game~ Thrones~ Clash~" \
  --data-urlencode "qauthor= George~ R.R.~ Martin~" \
  --data-urlencode "sort=books_id asc"

cmd: (在换行符之前,即使在“.”内)

代码语言:javascript
运行
AI代码解释
复制
curl --silent --get localhost:8983/api/schema-designer/query ^
  --data-urlencode "_=1658489222229" ^
  --data-urlencode "configSet=eDisMaxTest1" ^
  --data-urlencode 'q= +_query_:"{!edismax mm=75% df=name v=$qname}" ^
                       +_query_:"{!edismax mm=70% df=author v=$qauthor}" ^
                       +inStock:true' ^
  --data-urlencode "qname= Game~ Thrones~ Clash~" ^
  --data-urlencode "qauthor= George~ R.R.~ Martin~" ^
  --data-urlencode "sort=books_id asc"

答复:两本所需书籍

代码语言:javascript
运行
AI代码解释
复制
{
  ...
  "responseHeader":{
    ...
    "params":{
      "q":" +_query_:\"{!edismax mm=75% df=name v=$qname}\"\n
            +_query_:\"{!edismax mm=70% df=author v=$qauthor}\"\n
            +inStock:true",
      "qauthor":" George~ R.R.~ Martin~",
      "qname":" Game~ Thrones~ Clash~",
      "sort":"books_id asc",
      "configSet":"eDisMaxTest1",
      "wt":"javabin",
      "version":"2",
      "_":"1658489222229"}},
  "response":{"numFound":2,"start":0,"numFoundExact":true,"docs":[
      {
        "name":"Game Thrones Clash",
        "author":"George R.R. Martin",
        ...
        "books_id":553573403,
        "inStock":true},
      {
        "name":"Game Thrones",
        "author":"George Martin",
        ...
        "books_id":553573404,
        "inStock":true}]
  }}

参考文献

1嵌套查询分析器(Solr参考指南/查询指南/查询语法和解析器/其他查询解析器) https://solr.apache.org/guide/solr/latest/query-guide/other-parsers.html#nested-query-parser

Solr https://lucidworks.com/post/nested-queries-in-solr/中的2个嵌套查询

3个本地Params (Solr参考指南/查询指南/查询语法和解析器) https://solr.apache.org/guide/solr/latest/query-guide/local-params.html

4查询类型简短(Solr参考指南/查询指南/查询语法和解析器/本地Params) https://solr.apache.org/guide/solr/latest/query-guide/local-params.html#query-type-short-form

5扩展DisMax (eDisMax)查询分析器(Solr参考指南/查询指南/查询语法和解析器) https://solr.apache.org/guide/solr/latest/query-guide/edismax-query-parser.html

6mm(最小应该项匹配)参数(Solr参考指南/查询指南/查询语法和解析器/ DisMax查询分析器) https://solr.apache.org/guide/solr/latest/query-guide/dismax-query-parser.html#mm-minimum-should-match-parameter

7 df default field https://solr.apache.org/guide/solr/latest/query-guide/standard-query-parser.html#standard-query-parser-parameters

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72980125

复制
相关文章

相似问题

添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档