环境==> solr - solr-8.9.0,java版本"11.0.12“2021-07-20 LTS
下面的.csv文件是在solr中索引的
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”。
显示结果的标准有三个,只有符合下列所有三个标准的结果才能显示出来:
输出应包含以下结果。
0553573403 (name - 75% matched as well author 70% matched)
0553573404 (name - 75% matched as well author 70% matched)
以下books_id将不包含在输出中。
0553573405 (name - 75% matched but author not 70% matched)
我知道扩展的DisMax包含查询参数‘mm’(最小应该匹配)和模糊搜索功能,但是下面的查询给出了所有三个结果。
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查询或其他方式吗?
发布于 2022-07-22 18:07:16
嵌套查询可以为查询的不同部分指定不同的查询参数。
+_query_:"{!edismax mm=75% df=name} Game~ Thrones~ Clash~"
+_query_:"{!edismax mm=70% df=author} George~ R.R.~ Martin~"
+inStock:true
_query_:
作为前缀指定的(参见引用1、2)。{! ... }...
通过前缀查询字符串指定查询解析器及其参数。{!edismax}...
{!type=edismax}...
或仅为应项匹配(mm) 6:{!mm=75%}...
{!df=author}...
可以通过以下任一项指定需要这两个子查询的
+query1 +query2
query1 AND query2
(如果存在多个q=
参数,则添加debugQuery=true
参数显示只有一个是q=
参数)。
测试
使用本地Solr 9在架构设计器页面的云模式中再现测试的步骤:
solr-9.0.0/bin/solr start -e cloud
H 158
命名新模式:eDisMaxTest1
_default
H 265H 166
示例文档E 268
,过去的csv数据并单击分析Documents.
text_general
.
E 287
中,单击RunQuery
http://localhost:8983/api/schema-designer/query
d94(值可能不同)。H 295F 296
请求:一个查询字符串
bash: (\在换行符继续行之前,省略‘.’)
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: (在换行符之前,即使在“.”内)
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: (\在换行符继续行之前,省略‘.’)
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: (在换行符之前,即使在“.”内)
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"
答复:两本所需书籍
{
...
"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
https://stackoverflow.com/questions/72980125
复制相似问题