2011-08-29 111 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>