Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在SOLR中搜索多个字段_Solr - Fatal编程技术网

在SOLR中搜索多个字段

在SOLR中搜索多个字段,solr,Solr,我正在尝试搜索2个字段,而不必在查询中指定字段名。在myschema.xml中,我添加了两个字段,它们对应于数据库表中的两列 <field name="title" type="string" indexed="true" stored="true" required="true"/> <field name="description" type="string" indexed="true" stored="true"/> 此外,我还添加了第三个字段,我想将其用作

我正在尝试搜索2个字段,而不必在查询中指定字段名。在myschema.xml中,我添加了两个字段,它们对应于数据库表中的两列

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

此外,我还添加了第三个字段,我想将其用作“copyField”中的目标
以及“defaultSearchField”


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

尝试将
组合搜索类型更改为
文本
,然后重新生成索引。

可能会以相同的结果结束,但为了供您参考,我在schema.xml的结尾使用copyField(但我不认为顺序相关),语法如下:

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

下面是我如何处理它的。我没有使用*别名,而是定义了要复制到组合字段的字段。在我的正常字段(标题和描述)上,我也将多值设置为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>

标题
组合搜索

Hi-dev,您现在如何解决此问题?你能给出正确的答案吗?你试过了吗?它起作用了吗?我的意思是你能把两个字段复制成一个吗?就像你做了两个来源和一个目标一样?@Manurajada>你试过了吗?它能工作吗?<当然,它多年来一直在生产中工作。-->我的意思是你能把两个字段复制成一个吗!另一种解决方案是使用(e)Demax查询解析器。您可以在那里定义要搜索的字段。这可以在solrconfig.xml中设置,因此不需要额外的查询参数。
<field name="combinedSearch" type="string"
  <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>
     ...
<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>