2015-03-31 116 views
1

我正在使用Apache Solr進行搜索。我使用數據導入處理程序從mysql表導入數據。但是當我使用q=KOHLI insigned q=lastname:KOHLI時,我沒有得到任何結果。Apache Solr搜索

這裏是q=lastname:KOHLI

{ 
    "responseHeader": { 
     "status": 0, 
     "QTime": 1, 
     "params": { 
     "q": "lastname:KOHLI", 
     "indent": "true", 
     "wt": "json", 
     "_": "1427802213299" 
    } 
    }, 
    "response": { 
    "numFound": 1, 
    "start": 0, 
    "docs": [ 
     { 
     "lastname": "KOHLI", 
     "town": "DELHI", 
     "id": "2", 
     "firstname": "VIRAT", 
     "_version_": 1497158663291273200 
     } 
    ] 
    } 
} 

schema.xml中響應:

<copyField source="firstname" dest="text"/> 
<copyField source="lastname" dest="text"/> 
<copyField source="town" dest="text"/> 
<field name="firstname" type="text_general" indexed="true" stored="true"/> 
<field name="lastname" type="text_general" indexed="true" stored="true"/> 
<field name="town" type="text_general" indexed="true" stored="true"/>` 
+0

* text *是您的* defaultSearchField *? – alexf 2015-03-31 13:49:02

+0

@alexf是的,我想通過名字,姓氏或城鎮進行搜索。 – Nagendra 2015-03-31 13:52:22

+0

在你的* solrConfig.xml *中,你沒有使用查詢解析器? – alexf 2015-03-31 13:53:23

回答

1

當您不指定搜索字段時,它會搜索默認搜索字段。如果您想執行這樣的搜索,則可以創建新字段並複製您希望使其成爲搜索目標的所有其他字段,然後將其設置爲默認搜索字段。

這裏有一些資源:

+0

@semsem謝謝 – Nagendra 2015-03-31 13:39:38

+0

沒關係,如果你覺得對你有用的答案,簽字作爲一個答案。 @Nagendra – SaidbakR 2015-03-31 21:16:05

1

您使用的查詢解析器?如果是,請在您的文件solrconfig.xml中,您在requestHandler中使用的查詢字段是什麼? (qf參數)。如果你沒有你的領域姓氏,這是一個正常的行爲。

如果不使用查詢分析器,在文件schema.xml中,你有什麼defaultSearchField

您可以添加Solr文件的片段嗎?

0

這是因爲你沒有正確設置默認搜索字段。如果您沒有在「q」中傳遞字段名稱,它會將輸入搜索到您在項目的config文件中設置的默認字段。

要設置默認的字段,你可以做任何一種方式:

  1. 在你的schema.xml,改變您的問與答<defaultSearchField>id</defaultSearchField><defaultSearchField>lastname</defaultSearchField>q={!type=dismax qf=lastname}KOHLI

  2. 運行(刪除 「Q =」如果在網絡端口)

參考:

請參閱查詢類型短表

https://archive.apache.org/dist/lucene/solr/ref-guide/apache-solr-ref-guide-4.9.pdf

希望它可以幫助。謝謝。