【问题标题】:Solr query syntax for array field数组字段的 Solr 查询语法
【发布时间】:2013-03-25 12:52:20
【问题描述】:

如何在数组字段中搜索?

我正在使用具有默认设置的 solr 4.2。 我使用 SolrNet 索引了一些 html 和 pdf 文档。这是我使用管理员搜索 *:* 搜索时此类文档的示例结果

enter code here
<doc>
<str name="id">2</str>
<date name="last_modified">2011-12-19T17:33:25Z</date>
<str name="author">name</str>
<str name="author_s">name</str>
<arr name="title">
  <str>CALIFORNIA CODES</str>
</arr>
<arr name="content_type">
  <str>application/pdf</str>
</arr>
<str name="resourcename">T01041.pdf</str>
<arr name="content">
  <str> PDF text here </str>
</arr>
<long name="_version_">1431314431195742208</long>
</doc>

使用 content:* 搜索返回 0 个结果。

【问题讨论】:

    标签: solr solrnet solr-query-syntax


    【解决方案1】:

    您的问题的答案很简单。

    您的 Schema.xml 文件表明字段 name="content" indexed="false" 即您的内容字段不可搜索。因此,如果您在任何内容中搜索“内容”,它将返回 0 个结果。

    请更改您的 schema.xml 文件并将内容字段设置为 indexed="true",以便使字段可搜索。

    保存文件
    重启 Solr。
    清除索引。
    重新索引文档

    现在您可以搜索 content:*

    如果它解决了您的问题,请接受答案...

    【讨论】:

      【解决方案2】:

      text:* 有效。它返回我所有的文档。

      我从架构中得到了这个:

           <!-- Main body of document extracted by SolrCell.
              NOTE: This field is not indexed by default, since it is also copied to "text"
              using copyField below. This is to save space. Use this field for returning and
              highlighting document content. Use the "text" field to search the content. -->
         <field name="content" type="text_general" indexed="false" stored="true" multiValued="true"/>
      
      
         <!-- catchall field, containing all other searchable text fields (implemented
              via copyField further on in this schema  -->
         <field name="text" type="text_general" indexed="true" stored="false" multiValued="true"/>
      

      【讨论】:

        【解决方案3】:

        尝试使用content:[* TO *] 而不是content:*。这将获取所有具有字段content 非空的文档。

        对于查询数组/多值字段,这取决于你想做什么。如果您有一个多值字段,例如:

        <arr name="tag_names">
            <str>death</str>
            <str>history</str>
            <str>people</str>
            <str>historical figures</str>
            <str>assassinations</str>
        </arr>
        

        并且您想查找同时具有deathhistorytag_names 的文档,然后发出类似的查询

        q=tag_names:(death AND history)
        

        要执行 OR,请使用

        q=tag_names:(death OR history)
        

        【讨论】:

        • 您能发布content 字段的fieldType 及其定义吗?如果它不是索引字段,则无法对其进行搜索。
        • 我在我的回答中发布了它。你是对的,这就是问题所在。谢谢。
        • 拯救了我的一天!感恩!
        猜你喜欢
        • 1970-01-01
        • 2020-03-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多