2012-10-01 30 views
0

我配置了solr,因此它可以從postgres數據庫中索引記錄。它已成功上傳。如果我將查詢字符串作爲*:*傳遞,它將生成表中所有行的響應。但是,當我指定搜索,結果總是當查詢字符串*:*爲0在solr搜索中選擇不起作用

我的XML響應:

<?xml version="1.0" encoding="UTF-8" ?> 

<response> 
    <lst name="responseHeader"> 
    <int name="status">0</int> 
    <int name="QTime">0</int> 
    <lst name="params"> 
     <str name="q">*:*</str> 
    </lst> 
</lst> 
<result name="response" numFound="3" start="0"> 
<doc> 
<str name="names">sample1</str> 
<str name="sno">1</str> 
<str name="values">3</str> 
</doc> 
<doc> 
<str name="names">sample2</str> 
<str name="sno">2</str> 
<str name="values">2</str> 
</doc> 
<doc> 
<str name="names">sample3</str> 
<str name="sno">3</str> 
<str name="values">4</str> 
</doc> 
</result> 
</response> 

而我的迴應時,查詢字符串q=sample1是:

<?xml version="1.0" encoding="UTF-8" ?> 

<response> 
    <lst name="responseHeader"> 
    <int name="status">0</int> 
    <int name="QTime">0</int> 
    <lst name="params"> 
     <str name="q">*:*</str> 
    </lst> 
</lst> 
<result name="response" numFound="0" start="0" /> 
</response> 

謝謝提前。

回答

2

q,本身將在defaultSearchField(在schema.xml中)中定義的任何字段中進行搜索。

如果您要將所有有趣的文本複製到默認字段,則該搜索將起作用。或者,您可以在查詢中傳遞字段名稱。 q=names:sample1也應該返回結果。

+0

是的,但我在schema.xml中給了 names。但是,當我使用q = sample1時,它仍然沒有發揮作用。 – Boopathy

0

我運行了一個測試項目,它基於Solr 6.6.2中提供的默認示例以及MySql集成(假設它與您與postgres的集成有點相關)。我遇到了這個問題,事實證明這只是字段的命名。

在爲DataImportHandler配置文件(在大多數的「Solr教程索引數據庫」的教程,它被稱爲數據-config.xml中),該<field>元素的名稱也必須在schema.xml中文件。我使用了Solr附帶的默認示例中的配置,其中要查詢的字段是_text_

這是該線路數據-config.xml中文件如下: <field column="name" name="_text_"/>

數據-config.xml中

<dataConfig> 
    <dataSource type="JdbcDataSource" 
     driver="com.mysql.jdbc.Driver" 
     url="jdbc:mysql://localhost:3306/mydb1" 
     user="root" 
     password=""/> 
     <document> 
      <entity name="product" pk="id" 
       query="select id,name from products" 
       deltaImportQuery="SELECT id,name from products WHERE id='${dih.delta.id}'" 
       deltaQuery="SELECT id FROM products WHERE updated_at > '${dih.last_index_time}'" 
       > 
       <field column="id" name="id"/> 
       <field column="name" name="_text_"/> 
      </entity> 
     </document> 
</dataConfig> 

Schema.xml的(必須包含以下項):

<field name="_text_" type="text_general" indexed="true" stored="true"/>

修復後,查詢如/select?q = foo返回非空結果。