solr 4.7 使用记录

使用时与到的问题:

1,检查配置完全正确,数据只有删除消息,没有Add/Update 添加和修改信息。原因是dataimport.properties 文件的 last_index_time 属性时间,离当前时间太近, 导致没有数据。所以需要把时间与现在的间距长一些。
 
dataimport.proper

一、dataimport.properties 文件
#Thu Mar 30 13:52:16 GMT+08:00 2017last_index_time=2016-01-01 13\:52\:08message.last_index_time=2016-01-01 13\:52\:08二、/opt/soft/tomcat7solr/webapps/solr/db/core3-data-config.xml
<dataConfig>
     <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://IP:3306/cms" user="WEFWE" password="ig_WEFWEWEFWE" />
     <document name="messages">
         <entity name="message" pk="entity_id" transformer="ClobTransformer" 
                 query="SELECT 1 type ,ce.entity_id,ce.entity_desc,cn.news_subhead,ce.entity_url,ce.entity_time,date_format(ce.entity_updatetime, '%Y-%m-%d %H:%i:%s') time,cn.news_coverpic,ce.entity_category,ce.entity_channel,cn.news_keyword,cn.news_author,ce.entity_pid,CONCAT(cn.news_abstract,cn.news_keyword,cn.news_subhead) content FROM cms_entity ce,cms_news cn WHERE ce.entity_id=cn.entity_id AND ce.entity_type=2 AND ce.entity_status=2 AND   ce.entity_subtype=1 AND ce.entity_pid=100206667"
                 deltaQuery="select ce.entity_id from cms_entity ce,cms_news cn where ce.entity_id=cn.entity_id AND ce.entity_type=2 AND cn.news_referid=-1 AND ce.entity_status=2 AND ce.entity_updatetime > '${dataimporter.last_index_time}'"
                 deletedPkQuery="select ce.entity_id from cms_entity ce where ce.entity_type=2 AND ce.entity_status !=2"
                 deltaImportQuery="SELECT 1 type ,ce.entity_id,ce.entity_desc,cn.news_subhead,ce.entity_url,ce.entity_time,date_format(ce.entity_updatetime, '%Y-%m-%d %H:%i:%s') time,cn.news_coverpic,ce.entity_category,ce.entity_channel,cn.news_keyword,cn.news_author,ce.entity_pid,CONCAT(cn.news_abstract,cn.news_keyword,cn.news_subhead) content FROM cms_entity ce,cms_news cn WHERE ce.entity_id=cn.entity_id AND ce.entity_type=2 AND ce.entity_status=2 AND ce.entity_subtype=1 AND ce.entity_pid=100206667  AND ce.entity_id='${dataimporter.delta.entity_id}'"  
                 >
                         <field column="entity_id" name="id" />
                         <field column="time" name="time" />
                         <field column="news_keyword" name="keyword"/>
                         <field column="entity_desc" name="title" />
                         <field column="content" name="content" />
                         <field column="type" name="type" />
         </entity>
     </document>
 </dataConfig>
注意 不要用 Left join 语句。
三、solr.xml 文件

<?xml version="1.0" encoding="UTF-8" ?>
<solr persistent="false">
<cores adminPath="/admin/cores" host="${host:}" hostPort="${jetty.port:8983}" hostContext="${hostContext:solr}">
<core name="core0" instanceDir="core0" />
<core name="core1" instanceDir="core1" />
<core name="core2" instanceDir="core2" />
<core name="core3" instanceDir="core3" />
</cores>
</solr>

四、dataimport.properties



#################################################
# #
# dataimport scheduler properties #
# #
#################################################

# to sync or not to sync
# 1 - active; anything else - inactive 开启
syncEnabled=1

# which cores to schedule
# in a multi-core environment you can decide which cores you want syncronized
# leave empty or comment it out if using single-core deployment
#syncCores=game,resource
syncCores=core0,core3
# solr server name or IP address
# [defaults to localhost if empty]
server=IP

# solr server port
# [defaults to 80 if empty]
port=8081

# application name/context
# [defaults to current ServletContextListener's context (app) name]
webapp=/

# URL params [mandatory]
# remainder of URL
params=/select?qt=/dataimport&command=delta-import&clean=false&commit=true

# schedule interval
# number of minutes between two runs
# [defaults to 30 if empty] 分钟
interval=3

# 重做索引的时间间隔,单位分钟,默认7200,即1天;
# 为空,为0,或者注释掉:表示永不重做索引
reBuildIndexInterval=0

# 重做索引的参数
reBuildIndexParams=/select?qt=/dataimport&command=full-import&clean=true&commit=true

# 重做索引时间间隔的计时开始时间,第一次真正执行的时间=reBuildIndexBeginTime+reBuildIndexInterval*60*1000;
# 两种格式:2012-04-11 03:10:00 或者 03:10:00,后一种会自动补全日期部分为服务启动时的日期
reBuildIndexBeginTime=03:10:00
[root@svr31i conf]#


五,schema.xml 文件
<?xml version="1.0" ?>
<schema name="example core zero" version="1.1">
<types>
<fieldtype name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
<fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
<fieldtype name="textMaxWord" class="solr.TextField" positionIncrementGap="100">
<analyzer>
<tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="max-word" dicPath="dic"></tokenizer>
</analyzer>
</fieldtype>
</types>
<fields>
<field name="id" type="string" indexed="true" stored="true" multiValued="false" required="true"/>
<field name="type" type="string" indexed="true" stored="true" multiValued="false" />
<field name="name" type="string" indexed="true" stored="true" multiValued="false" />
<field name="core0" type="string" indexed="true" stored="true" multiValued="false" />
<field name="_version_" type="long" indexed="true" stored="true"/>
<field name="title" type="textMaxWord" indexed="true" stored="true" multiValued="false" />
<field name="time" type="string" indexed="true" stored="true"/>
<field name="keyword" type="string" indexed="true" stored="true"/>
<field name="content" type="string" indexed="true" stored="true" multiValued="false" />
</fields>

<!-- field to use to determine and enforce document uniqueness. -->
<uniqueKey>id</uniqueKey>

<!-- field for the QueryParser to use when an explicit fieldname is absent -->
<defaultSearchField>name</defaultSearchField>

<!-- SolrQueryParser configuration: defaultOperator="AND|OR" -->
<solrQueryParser defaultOperator="OR"/>
</schema>


六,solrconfig.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<!--
This is a stripped down config file used for a simple example...
It is *not* a good example to work from.
-->
<config>
<luceneMatchVersion>4.5</luceneMatchVersion>
<!-- The DirectoryFactory to use for indexes.
solr.StandardDirectoryFactory, the default, is filesystem based.
solr.RAMDirectoryFactory is memory based, not persistent, and doesn't work with replication. -->
<directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.StandardDirectoryFactory}"/>

<dataDir>${solr.core3.data.dir:}</dataDir>

<!-- To enable dynamic schema REST APIs, use the following for <schemaFactory>:

<schemaFactory class="ManagedIndexSchemaFactory">
<bool name="mutable">true</bool>
<str name="managedSchemaResourceName">managed-schema</str>
</schemaFactory>

When ManagedIndexSchemaFactory is specified, Solr will load the schema from
he resource named in 'managedSchemaResourceName', rather than from schema.xml.
Note that the managed schema resource CANNOT be named schema.xml. If the managed
schema does not exist, Solr will create it after reading schema.xml, then rename
'schema.xml' to 'schema.xml.bak'.

Do NOT hand edit the managed schema - external modifications will be ignored and
overwritten as a result of schema modification REST API calls.

When ManagedIndexSchemaFactory is specified with mutable = true, schema
modification REST API calls will be allowed; otherwise, error responses will be
sent back for these requests.
-->
<schemaFactory class="ClassicIndexSchemaFactory"/>

<updateHandler class="solr.DirectUpdateHandler2">
<updateLog>
<str name="dir">${solr.core3.data.dir:}</str>
</updateLog>
</updateHandler>

<!-- realtime get handler, guaranteed to return the latest stored fields
of any document, without the need to commit or open a new searcher. The current
implementation relies on the updateLog feature being enabled. -->
<requestHandler name="/get" class="solr.RealTimeGetHandler">
<lst name="defaults">
<str name="omitHeader">true</str>
</lst>
</requestHandler>


<requestDispatcher handleSelect="true" >
<requestParsers enableRemoteStreaming="false" multipartUploadLimitInKB="2048" formdataUploadLimitInKB="2048" />
</requestDispatcher>

<requestHandler name="standard" class="solr.StandardRequestHandler" default="true" />
<requestHandler name="/analysis/field" startup="lazy" class="solr.FieldAnalysisRequestHandler" />
<requestHandler name="/update" class="solr.UpdateRequestHandler" />
<requestHandler name="/admin/" class="org.apache.solr.handler.admin.AdminHandlers" />

<requestHandler name="/admin/ping" class="solr.PingRequestHandler">
<lst name="invariants">
<str name="q">solrpingquery</str>
</lst>
<lst name="defaults">
<str name="echoParams">all</str>
</lst>
</requestHandler>

<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">/opt/soft/tomcat7solr/webapps/solr/db/core3-data-config.xml</str>
</lst>
</requestHandler>

<!-- config for the admin interface -->
<admin>
<defaultQuery>solr</defaultQuery>
</admin>
<searchComponent class="solr.SpellCheckComponent" name="suggest">
<str name="queryAnalyzerFieldType">text_spell</str>
<lst name="spellchecker">
<str name="name">suggest</str>
<str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
<str name="lookupImpl">org.apache.solr.spelling.suggest.tst.TSTLookup</str>
<str name="field">suggestion</str>
<float name="threshold">0.0001</float>
<str name="comparatorClass">freq</str>
<str name="buildOnOptimize">true</str>
</lst>
</searchComponent>
<requestHandler class="org.apache.solr.handler.component.SearchHandler"
name="/suggest">
<lst name="defaults">
<str name="spellcheck">true</str>
<str name="spellcheck.dictionary">suggest</str>
<str name="spellcheck.onlyMorePopular">true</str>
<str name="spellcheck.extendedResults">false</str>
<str name="spellcheck.count">10</str>
<str name="spellcheck.collate">true</str>
</lst>
<arr name="components">
<str>suggest</str>
</arr>
</requestHandler>
<queryConverter name="phraseQueryConverter" class="org.apache.solr.spelling.SpellingQueryConverter"/>
</config>


删除solr索引数据,使用XML有两种写法:

1)

<delete><id>1</id></delete>
<commit/>

2)

<delete><query>id:1</query></delete>
<commit/>

删除所有索引,这样写就可以了:

<delete><query>*:*</query></delete>
<commit/>

注意:这个<commit/>节点不能少,否则删除动作的事务不会提交。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值