首页 文章

在SOLR中搜索多个字段

提问于
浏览
3

我试图搜索2个字段,而不必在查询中指定字段名称 . 在我的schema.xml中,我添加了2个字段,这些字段对应于数据库表中的2列 .

<field name="title" type="string" indexed="true" stored="true" required="true"/>
<field name="description" type="string" indexed="true" stored="true"/>

另外我添加了第3个字段,我想在"copyField"中用作目的地
并且作为"defaultSearchField"

<field name="combinedSearch" type="string" indexed="true" stored="true" multiValued="true"/>

<copyField source="*" dest="combinedSearch"/>

<uniqueKey>title</uniqueKey> 

<defaultSearchField>combinedSearch</defaultSearchField>

现在在Solr管理界面中,如果我输入一些 Headers ,它将返回结果,但如果我输入一些描述,它将不会返回任何内容 . 似乎只有第一个字段用于搜索 . 我是否以正确的方式使用copyField和defaultSearchField?我重新启动了solr服务器并重新生成了索引 . 谢谢 .

3 回答

  • 0

    可能它以相同的结果结束,但是对于您的信息,我在schema.xml的末尾使用copyField(但我不认为,顺序是相关的)在以下语法中:

    <copyField source="title" dest="combinedSearch" />
       <copyField source="description" dest="combinedSearch" />
    

    下一个:

    <field name="combinedSearch" type="string"
    

    如果 type="text" 是更好的选择取决于"string"的定义 . 如果您使用默认的fieldTypes, type="string" 可能更适合您的情况,因为对于 string ,默认情况下没有分析,这意味着(可能)也没有令牌化 .

    //更新

    另一种方法是使用(e)dsimax查询解析器而不是copyfields . 在 solrconfig.xml 上,您可以指定默认搜索的所有字段,如下所示:

    <requestHandler name="/select" class="solr.SearchHandler" default="true">
        <!-- default values for query parameters can be specified, these
             will be overridden by parameters in the request
          -->
         <lst name="defaults">
           <str name="defType">edismax</str>
           <float name="tie">0.01</float>
           <bool name="tv">true</bool>
           <str name="qf">
                 title^1 description^1
           </str>
         ...
    
  • 2

    尝试将 combinedSearch 类型更改为 text ,然后重新生成索引 .

  • 1

    这是我接近它的方式 . 我没有使用*别名,而是定义了要复制到我的组合字段的字段 . 我还在我的正常字段( Headers 和描述)上将multiValued设置为false . 我没有将字段定义为字符串,而是使用“text_general” - 对于我的普通字段和组合字段 .

    此外,我在组合字段上设置“stored = false”,因为我不需要返回值,因为它仅用于搜索 - 至少在我的情况下 .

    <field name="title" type="text_general" indexed="true" stored="true" required="true" multiValued="false" />
    <field name="description" type="text_general" indexed="true" stored="true" multiValued="false"/>
    
    <field name="combinedSearch" type="text_general" indexed="true" stored="false" multiValued="true"/>
    <copyField source="title" dest="combinedSearch"/>
    <copyField source="description" dest="combinedSearch"/>
    
    <uniqueKey>title</uniqueKey> 
    <defaultSearchField>combinedSearch</defaultSearchField>
    

相关问题