我無法將文檔從Mysql索引到Solr。DIH Mysql到Solr導入問題
我的配置:
數據-config.xml中
<dataConfig>
<dataSource type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://xxx?characterEncoding=utf8"
user="xxx"
password="xxx"/>
<document name="articledata">
<entity name="outer"
transformer="HTMLStripTransformer"
query="SELECT
id,kundenid,LOWER(title) as title,LOWER(content) as content,
DATE_FORMAT(cr,'%Y-%m-%dT%H:%i:%sZ') as cr,
lang
FROM articledata
WHERE
DATE(cr) BETWEEN DATE(DATE_SUB(now(),INTERVAL 3 DAY)) AND DATE(now())
AND content IS NOT NULL
ORDER BY DATE(cr) DESC">
<field column="id" name="id" />
<field column="kundenid" name="kundenid" />
<field column="title" name="title" />
<field column="content" name="content" stripHTML="true" />
<field column="cr" name="cr" />
<field column="lang" name="lang" />
</entity>
</document>
</dataConfig>
schema.xml中
<?xml version="1.0" ?>
<schema name="articledata core zero" version="1.1">
<types>
<fieldtype name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>
<fieldtype name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
<fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="dt" class="solr.TrieDateField" precisionStep="0" positionIncrementGap="0" />
<fieldType name="textgen" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
<filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="0"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
<filter class="solr.StopFilterFactory"
ignoreCase="true"
words="stopwords.txt"
enablePositionIncrements="true"
/>
<filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="0"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
</types>
<fields>
<field name="id" type="int" indexed="true" stored="true" required="true"/>
<field name="kundenid" type="int" indexed="true" stored="true" required="true"/>
<field name="title" type="string" indexed="true" stored="true" />
<field name="content" type="textgen" indexed="true" stored="true" />
<field name="cr" type="dt" indexed="true" stored="true" />
<field name="lang" type="string" indexed="true" stored="true" />
<field name="_version_" type="long" indexed="true" stored="true"/>
</fields>
<uniqueKey>id</uniqueKey>
<defaultSearchField>content</defaultSearchField>
<solrQueryParser defaultOperator="AND"/>
</schema>
利用這種結構,我得到的文件是這樣的:
"docs": [
{
"content": "[[email protected]",
"id": 20785923,
"cr": "2014-07-24T08:01:58Z",
"title": "general motors entdeckt neue mängel bei hunderttausenden wagen - news - alle aktuellen news - dpa-afx - general motors dl-,01 - onvista",
"kundenid": 1,
"_version_": 1474502436614832000
},
標題變索引正確
內容顯示爲廢話字符,無法搜索。
任何想法,我可以解決這個問題?
在此先感謝。
我發現問題正如你所說,內容字段是一個blob。我將內容列的查詢更改爲 CONVERT(LOWER(內容)使用utf8)作爲內容, – CuReSoft
它解決了您的問題嗎? –
是solr現在正確索引文檔。 – CuReSoft