2011-08-29 147 views
3

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

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

另外我加入,我想在“copyField”目标
,也为“defaultSearchField”

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

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

<uniqueKey>title</uniqueKey> 

<defaultSearchField>combinedSearch</defaultSearchField> 

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

+0

嗨开发,你现在怎么解决这个问题?你能发表正确的答案吗? –

回答

1

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

2

也许它在同一个结果结束,但对于您的信息,我使用copyField在schema.xml中的最后(但我不认为,订单是相关的)的语法如下:

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

下一个:

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

如果type="text"是更好的choise取决于 “串” 的定义。如果使用默认字段类型,则type="string"可能对您的情况更好,因为对于string,没有默认分析,这意味着(可能)也没有令牌字符。

//更新

的其他方式,而不是copyfields是使用(e)中dsimax查询解析器。在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> 
    ... 
+0

你试过了吗?它工作吗?我的意思是你可以将两个字段复制成一个吗?就像你做了两个来源和一个目标? – manurajhada

+2

@manurajhada>你试过了吗?它工作吗?<当然,它从事多年的生产工作。 ;-)>我的意思是你可以将两个字段复制成一个?<正确!另一种解决方案是使用(e)dismax查询解析器。在那里你可以定义你想要搜索的字段。这可以在solrconfig.xml中设置,这样不需要额外的查询参数。 http://wiki.apache.org/solr/DisMaxQParserPlugin#qf_.28Query_Fields.29 –

+0

@manurajhada我更新了我的答案.... –

0

以下是我走近它。我没有使用*别名,而是定义了要复制到我的组合字段的字段。我也在我的正常字段(标题和说明)上使用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>