搜索引擎Sorl

搜索引擎Sorl什么是 Sorl 在介绍 Sorl 之前先了解一下什么是 Lucene Lucene 是一个开放源代码的全文检索引擎工具包 即它不是一个完整的全文检索引擎 而是一个全文检索引擎的架构 提供了完整的查询引擎和索

大家好,欢迎来到IT知识分享网。

什么是Sorl?

在介绍Sorl之前先了解一下什么是Lucene!

Lucene是一个开放源代码的全文检索引擎工具包,即它不是一个完整的全文检索引擎,而是一个全文检索引擎的架构,提供了完整的查询引擎和索引引擎,部分文本分析引擎。

Solr是一个开源搜索平台,主要用于构建搜索应用程序。 它建立在Lucene(全文搜索引擎)之上。 Solr是企业级的,快速的和高度可扩展的。 使用Solr构建的应用程序非常复杂,可提供高性能。

Sorl配置IK分词器

步骤:

1、把IKAnalyzer2012FF_u1.jar 添加到 solr 工程的 lib 目录下

2、创建WEB-INF/classes文件夹  把扩展词典、停用词词典、配置文件放到 solr 工程的 WEB-INF/classes 目录下。

3、修改 Solrhome 的 schema.xml 文件,配置一个 FieldType,使用 IKAnalyzer

<fieldType name="text_ik" class="solr.TextField"> <analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/> </fieldType> 

Sorl配置域:

域的常用属性:

  • name:指定域的名称
  • type:指定域的类型
  • indexed:是否索引
  • stored:是否存储
  • required:是否必须
  • multiValued:是否多值

例如:

 <field name="item_goodsid" type="long" indexed="true" stored="true"/> <field name="item_title" type="text_ik" indexed="true" stored="true"/> 

复制域:

复制域的作用在于将某一个Field中的数据复制到另一个域中

例如:

<field name="item_keywords" type="text_ik" indexed="true" stored="false" multiValued="true"/> <copyField source="item_title" dest="item_keywords"/> <copyField source="item_category" dest="item_keywords"/> 

动态域:

当我们需要动态扩充字段时,我们需要使用动态域,例如

<dynamicField name="item_spec_*" type="string" indexed="true" stored="true" /> 

Spring Data Sorl :

Spring data Sorl依赖:

<dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-solr</artifactId> <version>1.5.5.RELEASE</version> </dependency> 

项目中添加配置文件:applicationContext-sorl.xml

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:solr="http://www.springframework.org/schema/data/solr" xsi:schemaLocation="http://www.springframework.org/schema/data/solr http://www.springframework.org/schema/data/solr/spring-solr-1.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- solr服务器地址 --> <solr:solr-server id="solrServer" url="http://127.0.0.1:8080/solr" /> <!-- solr模板,使用solr模板可对索引库进行CRUD的操作 --> <bean id="solrTemplate" class="org.springframework.data.solr.core.SolrTemplate"> <constructor-arg ref="solrServer" /> </bean> </beans> 

如果属性与配置文件定义的域名称不一致,需要在注解中指定域名称。用@Field注解在对应实体上加上对应的名称。

 

 

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/141856.html

(0)
上一篇 2025-05-14 15:33
下一篇 2025-05-14 15:45

相关推荐

发表回复

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

关注微信