【问题标题】:solr: how to join three cores?solr:如何加入三个核心?
【发布时间】:2018-09-18 06:35:25
【问题描述】:

我正在尝试根据两个相关核心的条件查询一个核心,但我没有得到任何结果。每个单独的连接都可以正常工作。

我应该如何表达一个基于两个核心加入的查询?

在 SQL 世界中,这被称为三张表的内连接以获得交集。

SQL 对应:

  SELECT *
  FROM proddev
  INNER JOIN department ON HMProductDevelopmentDepartment==id
  INNER JOIN season ON HMProductDevelopmentSeason==id

我正在运行 solr-7.3.1。查询在http://localhost:8983/solr/#/proddev/query中执行

 {!join from=id fromIndex=season to=HMProductDevelopmentSeason}name:"8-2018" AND _query_  {!join from=id fromIndex=department to=HMProductDevelopmentDepartment}DepartmentNumber:6515

主表:proddev

{
    "id":"48352.32064.2208.65165",
    "name":["0439370D"],
    "HMProductDevelopmentDepartment":["48352.32064.61248.42035"],
    "HMProductDevelopmentSeason":["48352.32064.24988.33959"],
    "HMCandidateForFileSync":[" FALSE    "],
    "PublishedDate":[" 11/14/2017 11:29:25 AM    "],
...
 }

相关核心:季节

{
    "id":"48352.32064.24988.33959",
    "name":["8-2018"],
    "_version_":1611866808030068736,
    "name_str":["8-2018"]}]
}

相关核心:部门

 {
    "id":"48352.32064.61248.42035",
    "name":["448"],
    "DepartmentNumber":[" 6515"],
    "_version_":1611923411375751168,
    "name_str":["448"],
    "DepartmentNumber_str":[" 6515"]}]
}

调试响应:

"responseHeader":{
"status":0,
"QTime":1,
"params":{
  "q":"{!join from=id fromIndex=season to=HMProductDevelopmentSeason}name:\"8-2018\" AND _query_  {!join from=id fromIndex=department to=HMProductDevelopmentDepartment}DepartmentNumber:6515",
  "debugQuery":"on",
  "_":"1537194871447"}},
"response":{"numFound":0,"start":0,"docs":[]
  },
  "debug":{
"rawquerystring":"{!join from=id fromIndex=season to=HMProductDevelopmentSeason}name:\"8-2018\" AND _query_  {!join from=id fromIndex=department to=HMProductDevelopmentDepartment}DepartmentNumber:6515",
"querystring":"{!join from=id fromIndex=season to=HMProductDevelopmentSeason}name:\"8-2018\" AND _query_  {!join from=id fromIndex=department to=HMProductDevelopmentDepartment}DepartmentNumber:6515",
"parsedquery":"JoinQuery({!join from=id to=HMProductDevelopmentSeason fromIndex=season}+name:\"8 2018\" +_text_:_query_ {!join from=id to=HMProductDevelopmentDepartment fromIndex=department}DepartmentNumber:6515)",
"parsedquery_toString":"{!join from=id to=HMProductDevelopmentSeason fromIndex=season}+name:\"8 2018\" +_text_:_query_ {!join from=id to=HMProductDevelopmentDepartment fromIndex=department}DepartmentNumber:6515",
"explain":{},

【问题讨论】:

    标签: apache solr lucene


    【解决方案1】:

    如果您想使用嵌套查询,您应该修复查询中的错误。 固定查询:

    {!join from=id fromIndex=season to=HMProductDevelopmentSeason}name:"8-2018" AND _query_:"{!join from=id fromIndex=department to=HMProductDevelopmentDepartment}DepartmentNumber:6515"
    

    或者您可以使用过滤查询进行第二次连接。

    链接:
    https://lucidworks.com/2009/03/31/nested-queries-in-solr/

    【讨论】:

    • 谢谢!当我将第二个连接放在 fq 字段中时它可以工作,但当我使用嵌套查询时它不起作用。当我使用嵌套查询时,我得到以下响应: { "responseHeader":{ ..."root-error-class","org.apache.solr.common.SolrException"], "msg":"undefined field: \"HMProductDevelopmentDepartment\"", "code":400}}
    • 新查询:{!join from=id fromIndex=season to=HMProductDevelopmentSeason}name:"8-2018" AND query:"{!join from=id fromIndex=部门 to=HMProductDevelopmentDepartment}DepartmentNumber:6515"
    • 我觉得你根本不需要嵌套,可以看这个帖子stackoverflow.com/questions/39916297/…
    猜你喜欢
    • 1970-01-01
    • 2018-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-19
    • 2019-06-18
    • 2014-10-11
    相关资源
    最近更新 更多