2011-03-15 63 views
1

我見過幾個問題上選擇正確的字段類型爲MySQL的相應列的數據類型,但我的問題是有點怪。我已經在text類型的MySQL的職位一欄,我已經試過相應field-type它在Solr的schema.xml例如string, text, text-ws。但是,無論何時使用DIH導入它,它都會作爲BLOB對象導入。我查了一下,這一點是text而不是varchar類型的字段只發生(他們獲得索引爲字符串)。因此,posts字段不可搜索。SOLR DIH導入MySQL的「文本」列作爲BLOB這裏

,我發現了這個問題,反覆搜索失敗後,當我做了一個Solr的查詢*:*搜索。樣品響應:

<result name="response" numFound="223" start="0" maxScore="1.0"> 
    <doc> 
    <float name="score">1.0</float> 
    <str name="solr_post_bio">[[email protected]</str> 
    <date name="solr_post_created_at">2011-02-21T07:02:55Z</date> 
    <str name="solr_post_email">[email protected]</str> 
    <str name="solr_post_first_name">Test</str> 
    <str name="solr_post_last_name">Account</str> 
    <str name="solr_post_message">[[email protected]</str> 
    <str name="solr_post_status_message_id">1</str> 
    </doc> 

編輯:

道歉爲不提供以下詳細信息。

data-config.xml

<document> 
    <entity name="posts" dataSource="jdbc" query="select 
     p.person_id as solr_post_person_id, 
     pr.first_name as solr_post_first_name, 
     pr.last_name as solr_post_last_name, 
     u.email as solr_post_email, 
     p.message as solr_post_message, 
     p.id as solr_post_status_message_id, 
     p.created_at as solr_post_created_at, 
     pr.bio as solr_post_bio 
     from posts p,users u,profiles pr where p.person_id = u.id and p.person_id = pr.person_id and p.type='StatusMessage'">    
      <field column="solr_post_person_id" /> 
     <field column="solr_post_first_name"/> 
     <field column="solr_post_last_name" /> 
     <field column="solr_post_email" /> 
     <field column="solr_post_message" /> 
     <field column="solr_post_status_message_id" /> 
     <field column="solr_post_created_at" /> 
     <field column="solr_post_bio"/> 
     </entity> 
    </document> 

schema.xml

<fields> 
    <field name="solr_post_status_message_id" type="string" indexed="true" stored="true" required="true" /> 
    <field name="solr_post_message" type="text_ws" indexed="true" stored="true" required="true" /> 
    <field name="solr_post_bio" type="text" indexed="false" stored="true" /> 
    <field name="solr_post_first_name" type="string" indexed="false" stored="true" /> 
    <field name="solr_post_last_name" type="string" indexed="false" stored="true" /> 
    <field name="solr_post_email" type="string" indexed="false" stored="true" /> 
    <field name="solr_post_created_at" type="date" indexed="false" stored="true" /> 
</fields> 
<uniqueKey>solr_post_status_message_id</uniqueKey> 
<defaultSearchField>solr_post_message</defaultSearchField> 
+0

請發表您的'schema.xml'和'數據config.xml'。另外,請在數據庫上運行一個查詢再次確認,該表實際上包含在列用於填充'solr_post_bio'正確的數據。 – nikhil500 2011-03-16 02:11:53

回答

0

我有同樣的問題。我所有的配置和模式都是正確的,但我仍然在短文本字段中獲取斑點。

多少頭刮後,我終於偶然發現了這種交流:http://qnalist.com/questions/624892/solr-dih-importing-mysql-text-column-as-a-blob

事實證明這樣的,或者在MySQL JDBC或錯誤導致罕見的情況下CHAR或VARCHAR字段爲BLOB露面代替。我懷疑這個bug是在MySQL中,因爲我正在使用一個相當老的版本。

在我的情況下,解決方法是將該值包裝在CONCAT()中,並將包含在CAST()中。這最終說服了MySQL,是的,我的文本欄確實是文本。

CAST(CONCAT('',your_column) AS CHAR(20)) 

我不知道你是否找到了解決您的問題,但是當我跑了進去,這個網頁在我的谷歌搜索過來的時候,所以我希望下可憐的人發現這個職位有幫助。