1
2
3
4
5
6
|
<
requestHandler
name
=
"/dataimport"
class
=
"org.apache.solr.handler.dataimport.DataImportHandler"
>
<
lst
name
=
"defaults"
>
<
str
name
=
"config"
>data-config.xml</
str
>
</
lst
>
</
requestHandler
>
|
1
|
<lib dir="../../../dist/" regex="solr-dataimporthandler-\d.*\.jar"/>
|
1
|
<lib dir="../../../dist/" regex="solr-cell-\d.*\.jar" />
|
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
dataConfig
>
<
dataSource
type
=
"JdbcDataSource"
driver
=
"com.mysql.jdbc.Driver"
url
=
"jdbc:mysql://localhost:3306/django_blog"
user
=
"root"
password
=
""
/>
<
document
name
=
"blog"
>
<
entity
name
=
"blog_blog"
pk
=
"id"
query
=
"select id,title,content from blog_blog"
deltaImportQuery
=
"select id,title,content from blog_blog where ID='${dataimporter.delta.id}'"
deltaQuery="select id from blog_blog where add_time > '${dataimporter.last_index_time}'"
deletedPkQuery="select id from blog_blog where id=0">
<
field
column
=
"id"
name
=
"id"
/>
<
field
column
=
"title"
name
=
"title"
/>
<
field
column
=
"content"
name
=
"content"
/>
</
entity
>
</
document
>
</
dataConfig
>
|
<!-- mysql -->
<
field
name
=
"id"
type
=
"string"
indexed
=
"true"
stored
=
"true"
required
=
"true"
/>
<
field
name
=
"title"
type
=
"text_cn"
indexed
=
"true"
stored
=
"true"
termVectors
=
"true"
termPositions
=
"true"
termOffsets
=
"true"
/>
<
field
name
=
"content"
type
=
"text_cn"
indexed
=
"true"
stored
=
"true"
termVectors
=
"true"
termPositions
=
"true"
termOffsets
=
"true"
/>
<!-- mysql -->
|
参考:
<code>git clone https://github.com/10gen-labs/mongo-connector.git cd mongo-connector #安装前修改mongo_connector/constants.py的变量:设置DEFAULT_COMMIT_INTERVAL = 0 python setup.py install </code>
默认是不会自动提交了,这里设置成自动提交,否则mongodb数据库更新,索引这边没法同时更新,或者在命令行中可以指定是否自动提交,不过我现在还没发现。
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
schema
name
=
"example"
version
=
"1.5"
>
<
field
name
=
"_version_"
type
=
"long"
indexed
=
"true"
stored
=
"true"
/>
<
field
name
=
"_id"
type
=
"string"
indexed
=
"true"
stored
=
"true"
required
=
"true"
multiValued
=
"false"
/>
<
field
name
=
"body"
type
=
"string"
indexed
=
"true"
stored
=
"true"
/>
<
field
name
=
"title"
type
=
"string"
indexed
=
"true"
stored
=
"true"
multiValued
=
"true"
/>
<
field
name
=
"text"
type
=
"text_general"
indexed
=
"true"
stored
=
"false"
multiValued
=
"true"
/>
<
uniqueKey
>_id</
uniqueKey
>
<
defaultSearchField
>title</
defaultSearchField
>
<
solrQueryParser
defaultOperator
=
"OR"
/>
<
fieldType
name
=
"string"
class
=
"solr.StrField"
sortMissingLast
=
"true"
/>
<
fieldType
name
=
"long"
class
=
"solr.TrieLongField"
precisionStep
=
"0"
positionIncrementGap
=
"0"
/>
<
fieldType
name
=
"text_general"
class
=
"solr.TextField"
positionIncrementGap
=
"100"
>
<
analyzer
type
=
"index"
>
<
tokenizer
class
=
"solr.StandardTokenizerFactory"
/>
<
filter
class
=
"solr.StopFilterFactory"
ignoreCase
=
"true"
words
=
"stopwords.txt"
/>
<
filter
class
=
"solr.LowerCaseFilterFactory"
/>
</
analyzer
>
<
analyzer
type
=
"query"
>
<
tokenizer
class
=
"solr.StandardTokenizerFactory"
/>
<
filter
class
=
"solr.StopFilterFactory"
ignoreCase
=
"true"
words
=
"stopwords.txt"
/>
<
filter
class
=
"solr.SynonymFilterFactory"
synonyms
=
"synonyms.txt"
ignoreCase
=
"true"
expand
=
"true"
/>
<
filter
class
=
"solr.LowerCaseFilterFactory"
/>
</
analyzer
>
</
fieldType
>
</
schema
>
|
<code>mongod --replSet myDevReplSet --smallfiles </code>
初始化:rs.initiate()
<code>E:\Users\liuzhijun\workspace\mongo-connector\mongo_connector\doc_managers>mongo-connector -m localhost:27017 -t http://localhost:8983/solr/collection2 -n s_soccer.person -u id -d ./solr_doc_manager.py </code>
注意:mongodb通常使用_id
作为uniquekey,而Solrmore使用id
作为uniquekey,如果不做处理,索引文件时将会失败,有两种方式来处理这个问题:
--unique-key=id
到mongo-connector,Mongo Connector 就可以翻译把_id
转换到id
。<code><uniqueKey>id<uniqueKey> </code>
替换成
<code><uniqueKey>_id</uniqueKey> </code>
同时还要定义一个_id
的字段:
<code><field name="_id" type="string" indexed="true" stored="true" /> </code>
<code>2014-06-18 12:30:36,648 - ERROR - OplogThread: Last entry no longer in oplog cannot recover! Collection(Database(MongoClient('localhost', 27017), u'local'), u'oplog.rs') </code>
清空E:\Users\liuzhijun\workspace\mongo-connector\mongo_connector\doc_managers\config.txt中的内容,需要删除索引目录下的文件重新启动