0
点赞
收藏
分享

微信扫一扫

solr4.0环境搭建


服务器:tomcat6

  JDK   :1.6

 SOLR :4.0

中文分词器 :ik-analyzer,mmseg4j

 

安装:目前mmseg4j的版本是mmseg4j-1.9.0.v20120712-SNAPSHOT,经过测试,发现这个版本有bug:

java.lang.RuntimeException: java.lang.NoSuchMethodError: org.apache.l
ucene.analysis.Tokenizer.reset(Ljava/io/Reader;)V


由于solr4.0对其中的有些类与方法做了调整,所以还是等待mmseg4j新版本修复吧。果断使用了ik-analyzer。



一、将apache-solr-4.0.0\example\webapps\solr.war放在tomcat的webapps下启动服务器解压该war包,另外还需要增加几个jar包:



apache-solr-dataimporthandler-4.0.0.jar
 
 
apache-solr-dataimporthandler-extras-4.0.0.jar



这两个jar包可以在solr的dist中可以找到



另外还需要相应数据库的驱动包,比如



mysql-connector-java-5.1.13-bin.jar



二、将apache-solr-4.0.0\example下的solr拷贝至apache-tomcat-6.0.29-solr\bin下



三、在apache-tomcat-6.0.29-solr\bin\solr\collection1\conf下的solrconfig.xml增加以下数据库配置



 

1. <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">       
2. <lst name="defaults">       
3. <str name="config">data-config.xml</str>       
4. </lst>       
5. </requestHandler>


四、将apache-tomcat-6.0.29-solr\bin\solr\collection1\conf下增加data-config.xml文件,内容如下:



 

1. <dataConfig>    
2. <dataSource type="JdbcDataSource"    
3. driver="com.mysql.jdbc.Driver"    
4. url="jdbc:mysql://localhost:3306/solrdb"    
5. user="root"    
6. password="888888"/>    
7. <document name="content">    
8. <entity name="node" query="select id,author,title,content from solrdb">    
9. <field column="id" name="id" />    
10. <field column="author" name="author" />    
11. <field column="title" name="title" />    
12. <field column="content" name="content" />  
13. </entity>    
14. </document>    
15. </dataConfig>


 



五、增加中文分词器,ik-analyzer的配置如下:



它的安装部署十分简单,将IKAnalyzer2012.jar部署亍项目的lib目录中;IKAnalyzer.cfg.xml不stopword.dic文件放置在class根目录(对于web项目,通常是WEB-I NF/classes目彔,同hibernate、log4j等配置文件相同)下即可



solr4.0中schema.xml配置解析器:


 


1. <schema name="example" version="1.1">   
2.     ……   
3. <fieldType name="text" class="solr.TextField">   
4. <analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/>   
5. </fieldType>  
6.     ……   
7. </schema>


六、schema.xml完整配置:


 


1. <?xml version="1.0" encoding="UTF-8" ?>    
2. <schema name="example" version="1.5">    
3. <types>        
4.   
5. <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>  
6.   
7.     
8. <fieldType name="string" class="solr.StrField" sortMissingLast="true" />   
9. <!-- IKAnalyzer 配置 -->  
10. <fieldType name="text" class="solr.TextField">   
11. <analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/>   
12. </fieldType>  
13.      
14. </types>    
15.     
16.     
17. <fields>    
18. <field name="id" type="string" indexed="true" stored="true" required="true" />   
19. <field name="author" type="text" indexed="true" stored="true" multiValued="false"/>    
20. <field name="title" type="text" indexed="true" stored="true" multiValued="false"/>    
21. <field name="content" type="text" indexed="true" stored="true" multiValued="false" />    
22. <field name="_version_" type="long" indexed="true" stored="true"/>  
23. </fields>    
24.     
25. <uniqueKey>id</uniqueKey>    
26. <defaultSearchField>content</defaultSearchField>    
27. <solrQueryParser defaultOperator="OR"/>    
28. <copyField source="title" dest="content"/>    
29. <copyField source="author" dest="content"/>  
30.   
31.     
32. </schema>


解析:multiValued的个人理解是配置true则返回单条数据,false则可以返回多条,以后深入理解了再详解。defaultSearchField配置默认搜索索引,copyField可以讲    title、author字段添加至content默认搜索中

解析:multiValued的个人理解是配置true则返回单条数据,false则可以返回多条,以后深入理解了再详解。defaultSearchField配置默认搜索索引,copyField可以讲    title、author字段添加至content默认搜索中

七、登录管理页面:

中文分词器分词的示例:

query示例:


举报

相关推荐

0 条评论