sorl入门

sorl入门本教程是从别人的基础上借鉴整理的 Solr 是一个独立的企业级搜索应用服务器 它对外提供 API 接口 用户可以通过 http 请求 向搜索引擎服务器提交一定格式的 XML 文件 生成索引 solr 生成倒排索引 数据库生成的索引是二叉树索引 效率差距很大 也可以通过 HttpGet 操作提出查找请求 并得到 XML 格式的返回结果 Solr 是一个类似于 Google 或者 Bing 的全文检索引擎 Solr 是与搜索引擎

本教程是从别人的基础上借鉴整理的

一、solr安装

<env-entry><env-entry-name>solr/home</env-entry-name><env-entry-value>D:/testsolr/solr_home/solr</env-entry-value><env-entry-type>java.lang.String</env-entry-type></env-entry>

 

二、创建第一个core

三、solr分词

 

<fieldtype name=“textComplex” class=“solr.TextField” positionIncrementGap=“100”><analyzer><tokenizer class=“com.chenlb.mmseg4j.solr.MMSegTokenizerFactory” mode=“complex” dicPath=“D:/testsolr/solr_home/solr/dic”>
tokenizer
>
analyzer
>
fieldtype
><fieldtype name=“textMaxWord” class=“solr.TextField” positionIncrementGap=“100”><analyzer><tokenizer class=“com.chenlb.mmseg4j.solr.MMSegTokenizerFactory” mode=“maxword” dicPath=“D:/testsolr/solr_home/solr/dic”>
tokenizer
>
analyzer
>
fieldtype
><fieldtype name=“textSimple” class=“solr.TextField” positionIncrementGap=“100”><analyzer><tokenizer class=“com.chenlb.mmseg4j.solr.MMSegTokenizerFactory” mode=“simple” dicPath=“D:/testsolr/solr_home/solr/dic”>
tokenizer
>
analyzer
>
fieldtype
>

 
   
     "name" 
    type= 
    "textMaxWord" indexed= 
    "true" stored= 
    "true" multiValued= 
    "true" /> 
    
      "description" 
     type= 
     "textMaxWord" indexed= 
     "true" stored= 
     "true" multiValued= 
     "true" /> 
     
   
  • 1
  • 2
  • 1
  • 2

四、solr连接数据库

 

CREATE TABLE `test_person` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(50) DEFAULT NULL COMMENT '姓名', `description` varchar(500) DEFAULT NULL COMMENT '简介', PRIMARY KEY (`id`) ); insert into test_person(name,description) values('周星驰','香港著名喜剧演员'); insert into test_person(name,description) values('周润发','香港著名演员'); insert into test_person(name,description) values('周节能','台湾著名歌手,号称音乐天王'); insert into test_person(name,description) values('成龙','香港著名动作演员'); insert into test_person(name,description) values('山本一木','日本鬼子'); insert into test_person(name,description) values('仓木麻衣','日本歌手');
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
 
     <dataConfig> <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/test" user="root" password="jhp123" /> <document name="messages"> <entity name="message" transformer="ClobTransformer" query="select * from test_peoson where name like '%${dataimporter.request.name}%'"> <field column="id" name="id" /> <field column="name" name="name" /> <field column="description" name="description" />  
    entity>  
    document>  
    dataConfig>




url=”jdbc:mysql://localhost:3306/test” user=”root” password=”123” 这里配置了 mysql 的连接路径 , 用户名 , 密码

 
   
     "name" 
    name= 
    "name" /> 这里配置的是数据库里要索引的字段, 注意 
    name是在分词的第 
    4 步配置的,同时只有这样匹配的字段最终solr才会查询显示出来,所以需要用到的字段必须在该文件中 
    
      "*" 
     name= 
     "*" />配置才可以; 
     
   
  • 1
  • 1

3、在D:\testsolr\solr_home\solr\my_core\conf\schema.xml文件中添加如下字段信息:

 
   
     "name" 
    type= 
    "textMaxWord" indexed= 
    "true" stored= 
    "true" multiValued= 
    "true" /> 
    
      "description" 
     type= 
     "textMaxWord" indexed= 
     "true" stored= 
     "true" multiValued= 
     "true" /> 
     
   
  • 1
  • 2
  • 1
  • 2
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler"> <lst name="defaults"> <str name="config">D:/testsolr/solr_home/solr/my_core/conf/solr-data-config.xml 
    str>  
    lst>  
    requestHandler>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5

solr查询参数具体参考:http://www.cnblogs.com/zhangweizhong/p/5056884.html

 

solr在Java中的使用:http://blog.csdn.net/u0/article/details/

一、solr安装

 <env-entry> <env-entry-name>solr/home</env-entry-name> <env-entry-value>D:/testsolr/solr_home/solr</env-entry-value> <env-entry-type>java.lang.String</env-entry-type> </env-entry>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5

二、创建第一个core

三、solr分词

<fieldtype name="textComplex" class="solr.TextField" positionIncrementGap="100"> <analyzer> <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="complex" dicPath="D:/testsolr/solr_home/solr/dic">  
    tokenizer>  
    analyzer>  
    fieldtype> <fieldtype name="textMaxWord" class="solr.TextField" positionIncrementGap="100"> <analyzer> <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="maxword" dicPath="D:/testsolr/solr_home/solr/dic">  
    tokenizer>  
    analyzer>  
    fieldtype> <fieldtype name="textSimple" class="solr.TextField" positionIncrementGap="100"> <analyzer> <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="simple" dicPath="D:/testsolr/solr_home/solr/dic">  
    tokenizer>  
    analyzer>  
    fieldtype>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
 
   
     "name" 
    type= 
    "textMaxWord" indexed= 
    "true" stored= 
    "true" multiValued= 
    "true" /> 
    
      "description" 
     type= 
     "textMaxWord" indexed= 
     "true" stored= 
     "true" multiValued= 
     "true" /> 
     
   
  • 1
  • 2
  • 1
  • 2

四、solr连接数据库

CREATE TABLE `test_person` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(50) DEFAULT NULL COMMENT '姓名', `description` varchar(500) DEFAULT NULL COMMENT '简介', PRIMARY KEY (`id`) ); insert into test_person(name,description) values('周星驰','香港著名喜剧演员'); insert into test_person(name,description) values('周润发','香港著名演员'); insert into test_person(name,description) values('周节能','台湾著名歌手,号称音乐天王'); insert into test_person(name,description) values('成龙','香港著名动作演员'); insert into test_person(name,description) values('山本一木','日本鬼子'); insert into test_person(name,description) values('仓木麻衣','日本歌手');
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
 
     <dataConfig> <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/test" user="root" password="jhp123" /> <document name="messages"> <entity name="message" transformer="ClobTransformer" query="select * from test_peoson where name like '%${dataimporter.request.name}%'"> <field column="id" name="id" /> <field column="name" name="name" /> <field column="description" name="description" />  
    entity>  
    document>  
    dataConfig>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

url=”jdbc:mysql://localhost:3306/test” user=”root” password=”123” 这里配置了 mysql 的连接路径 , 用户名 , 密码

 
   
     "name" 
    name= 
    "name" /> 这里配置的是数据库里要索引的字段, 注意 
    name是在分词的第 
    4 步配置的,同时只有这样匹配的字段最终solr才会查询显示出来,所以需要用到的字段必须在该文件中 
    
      "*" 
     name= 
     "*" />配置才可以; 
     
   
  • 1
  • 1

3、在D:\testsolr\solr_home\solr\my_core\conf\schema.xml文件中添加如下字段信息:

 
   
     "name" 
    type= 
    "textMaxWord" indexed= 
    "true" stored= 
    "true" multiValued= 
    "true" /> 
    
      "description" 
     type= 
     "textMaxWord" indexed= 
     "true" stored= 
     "true" multiValued= 
     "true" /> 
     
   
  • 1
  • 2
  • 1
  • 2
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler"> <lst name="defaults"> <str name="config">D:/testsolr/solr_home/solr/my_core/conf/solr-data-config.xml 
    str>  
    lst>  
    requestHandler>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5

solr查询参数具体参考:http://www.cnblogs.com/zhangweizhong/p/5056884.html

solr在Java中的使用:http://blog.csdn.net/u0/article/details/

转载于:https://www.cnblogs.com/juochiu/p/6250425.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/220809.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月17日 下午7:36
下一篇 2026年3月17日 下午7:36


相关推荐

  • mybatis code helper pro 2.9 激活[最新免费获取]

    (mybatis code helper pro 2.9 激活)2021最新分享一个能用的的激活码出来,希望能帮到需要激活的朋友。目前这个是能用的,但是用的人多了之后也会失效,会不定时更新的,大家持续关注此网站~IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html…

    2022年3月31日
    1.3K
  • AI 绘画 + 小红书变现:从 0 到 1 的实战指南附 DeepSeek 工具包 + 变现 SOP

    AI 绘画 + 小红书变现:从 0 到 1 的实战指南附 DeepSeek 工具包 + 变现 SOP

    2026年3月15日
    3
  • 2021山东安全员c证考试题库_C类安全员

    2021山东安全员c证考试题库_C类安全员题库来源:安全生产模拟考试一点通公众号小程序2022山东省安全员C证培训试题为山东省安全员C证判断题的新全考试题型!2022年山东省安全员C证考题及答案根据山东省安全员C证考试教材。山东省安全员C证复审模拟考试随时根据安全生产模拟考试一点通上手机同步练习。1、【多选题】一般模板工程通常由()等组成。(ABD)A、面板B、支架C、加固件D、连接件E、螺栓2、【多选题】下列沥青洒布车阀门及油路符合要求的是()。(ABCDE)A、各操作部分应灵活有效,各阀的…

    2025年9月24日
    7
  • iostat命令详解参数_iostat命令的dm

    iostat命令详解参数_iostat命令的dmiostat命令详解iostat用于输出CPU和磁盘输入输出、分区、网络文件系统NFS相关的统计信息。iostat命令用于监控系统设备的输入/输出情况,并生成报告,以便根据统计报告修改系统配置,获取更优的性能。命令格式:iostat[-c][-d][-N][-n][-h][-k|-m][-t][-V][-x][-z][device

    2022年10月6日
    6
  • c++酒店管理系统源代码_c语言酒店管理系统实验报告

    c++酒店管理系统源代码_c语言酒店管理系统实验报告现今大多数宾馆所提供的服务样式都各式各样,规模大小也是各有不同,但是归总下来,不可或缺的两类模块还是顾客和工作人员。由于对宾馆行业内部没有很深刻的理解,此次系统设计包括数据库和功能模块都是根据网上收集到的材料和个人认知上,简单模仿和具体实现的。为满宾馆管理的实际需求,本系统主要实现以下功能:入住登记:登记所入住房间号码,登记顾客入住时间,退房时间,个人信息(身份证号,手机号,姓名)退房办理:输入已经入住的房间号,确认完毕即可退房。房间查询:管理员输入正确的密码后即可对房间状态查询,和具体入住信息查

    2026年3月4日
    6
  • 2021美赛A题解题思路(Fungi)

    2021美赛A题解题思路(Fungi)准时赴约。等待开题中……

    2022年4月28日
    51

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号