【问题标题】:Solr filter query not working on fieldSolr 过滤器查询不适用于字段
【发布时间】:2015-09-03 14:55:02
【问题描述】:

我有一个包含一些字段(见下文)和语言字段的 Solr 设置。我只想返回语言为nl_NL 的结果。

但是,如果我对 /solr/client/query?q=test&fq=language:nl_NL 进行过滤查询,我将得不到任何结果。

fq 似乎没有在这个特定领域工作。但是,/solr/client/query?q=test&fq=id:1 上的查询工作正常。

过滤查询在字段上工作是否有任何特殊要求?这是我的schema.xml的概述。

<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<field name="title" type="text_nl" indexed="false" stored="true" />
<field name="content" type="text_nl" indexed="false" stored="true" multiValued="true" />
<field name="permalink" type="string" indexed="false" stored="true"/>
<field name="image" type="string" indexed="false" stored="true"/>
<field name="date" type="tdate" indexed="true" stored="true"/>
<field name="category" type="string" indexed="false" stored="true"/>
<field name="language" type="string" indexed="false" stored="true" />

使用 id 上带有 fq 的查询时的结果是:

    {
  "responseHeader":{
    "status":0,
    "QTime":4,
    "params":{
      "q":"test",
      "fq":"id:3968"}},
  "response":{"numFound":1,"start":0,"docs":[
      {
        "id":"3968",
        "title":"Scotch en Soda",
        "permalink":"http://www.example.com/merken/scotch-soda/",
        "image":"http://www.example.com/SS15-SCOTCH-SODA-BRAND-PAGE-150x150.jpg",
        "date":"2015-06-22T16:02:47Z",
        "category":"brands",
        "language":"nl_NL"}]
  }}

【问题讨论】:

  • 你能粘贴第二个查询的结果,即“/solr/client/query?q=test&fq=id:1”
  • 您能确认nl_NL 是您要搜索的确切(区分大小写)文本吗?
  • 我添加了对 id 进行过滤查询的结果。我还可以确认 nl_NL 是我要搜索的确切区分大小写的文本。
  • 您的架构说“语言”不是多值字段。但"language":["nl_NL"] 包含方括号。你能说说为什么吗?
  • 语言字段 - 索引:假????如果您想使用此字段进行搜索,这应该是正确的..

标签: solr


【解决方案1】:

最初我虽然是语言字段的 fieldType 问题,但事实并非如此。由于字段类型是字符串,请确保您没有提及过滤器中语言的字符串部分。

无论在索引时添加了什么值,它都必须与过滤器完全相同。那么它会为你工作。

【讨论】:

  • 我不确定您所说的“未提及过滤器中语言的字符串部分”是什么意思。您的意思是在 fq 中不包括“语言”吗?
  • 我最后测试了相同的...它工作正常唯一的区别是我有不同的 fieldType
  • 您使用哪种字段类型?
  • 这里是我使用的字段类型
【解决方案2】:

在语言字段上添加一个 index=true 字段就可以了。谢谢 Suhel Meman!

【讨论】:

    猜你喜欢
    • 2023-01-04
    • 2016-12-24
    • 2013-03-22
    • 1970-01-01
    • 1970-01-01
    • 2019-11-01
    • 1970-01-01
    • 2012-02-02
    • 1970-01-01
    相关资源
    最近更新 更多