• 完成搜索系统功能(十五)solr的安装以及搜索功能的构思


    1.有关搜索功能的构思(有关solr 以及 IK Analyzer 的下载链接 http://pan.baidu.com/s/1i43DOW1 密码:u5gg)

    1.1 配置solr服务,设置端口为8080 然后在solr服务加入所需要的字段

    1.2 建立jingxi-reach项目

    1.3 写一个serviceimpl 用于将数据库的数据写进solr索引库中

        1.3.1 新建一个mapper  以及一个关于mapper的 xml文件(xml文件写的是一句sql语句因为是 多表查询 所以不能调用jingxi-backend- mapper中的mapper)

        1.3.2 建立一个pojo类 主要的字段都是自己想 要的字段 就是包括描述

        1.3.3 写一个serviceimpl用于实现将数据库的 内容写入到solr的索引库中,调用mapper服 务进行数据库查询返回的是list,循环list 内的数据并且实例一个   SolrInputDocument, 将list的内容循环赋值给SolrInputDocument 最后将SolrInputDocument一个一个的加入 solr索引库中     

        1.3.4 写一个controller实现这个方法

    1.4 关于searchimpl的实现

        1.4.1 写一个SearchDaoimpl[(参数为SolrQuery query)(传入querry然后返回结果集) ]

        1.4.2  根据查询条件查询索引库 取结果 

        1.4.3 实例一个pojo 然后循环结果并且赋值给pojo ,将很多的pojo放在list中 最后用SearchResult 进行包装

        1.4.4 返回这个SearchResult

    1.5 关于SearchServiceImpl的实现

        1.5.1 SearchServiceImpl[ 参数为(String queryString, int page, int rows)]

        1.5.2 新建一个solrquery对象 然后设置query的各 种配置例如分页 搜索域等,最后调用 Searchdaoimpl返回的是SearchResult

    1.6 关于jingxi-protal调用jingxi-reach的服务

       1.6.1 在jingxi-protal中的searchServiceimpl 参数为(querystring 以及page)

       1.6.2 通过httpclient调用jingxi-search的 controller,最后改impl返回的是一个 searchresult

       1.6.3 在jingxi-protal的controller写一个 controller(参数 querystring 以及page( 默认为1)) )

       1.6.4 调用searchServiceimpl的方法,将返回的searchresult的内容存在session中 ,最后由页面自动去读取就可以了

     2. 使用solr实现全文搜索          

    2.1    Solr是什么?

    Solr 是Apache下的一个顶级开源项目,采用Java开发,它是基于Lucene的全文搜索服务器。Solr提供了比Lucene更为丰富的查询语言,同时实现了可配置、可扩展,并对索引、搜索性能进行了优化。

    Solr是一个全文检索服务器,只需要进行配置就可以实现全文检索服务。

    2.2   Solr的安装及配置

    在本window的tomcat9中建立solr服务,然后设立端口为8080  ps 如果前面的项目中有用到8080端口,可以对端口进行适当的调整。

    第一步: 在solr的官网下载solr  然后进行解压

    第二部: 把/root/solr-4.10.3/dist/solr-4.10.3.war包部署到tomcat下。并改名为solr.war

    第三步: 解压war包。启动tomcat自动解压。关闭tomcat。删除solr.war.

    第四步: 把/root/solr-4.10.3/example/lib/ext 目录下所有的jar包复制到solr工程中

    第五步: 创建solrhome。Solrhome是存放solr服务器所有配置文件的目录,solrhome的位置如下

     第六步: 告诉solr服务器solrhome的位置。需要修改solr工程的web.xml文件。

    第七步: 启动tomcat  打开localhost:8080/solr

    输入网址,看到这个页面就说明solr已经安装成功了。

    第八步: 配置业务字段

    1、在solr中默认是中文分析器,需要手工配置。配置一个FieldType,在FieldType中指定中文分析器。

    2、Solr中的字段必须是先定义后使用

    3、使用IK-Analyzer。把分析器的文件夹上传到服务器,需要把分析器的jar包添加到solr工程中。

    4、需要把IKAnalyzer需要的扩展词典及停用词词典、配置文件复制到solr工程的classpath。cp IKAnalyzer.cfg.xml ext_stopword.dic mydict.dic /usr/local/solr/tomcat/webapps/solr/WEB-INF/classes

    5、配置fieldType。需要在solrhome/collection1/conf/schema.xml中配置。技巧:使用vi、vim跳转到文档开头gg。跳转到文档末尾:G

    2.3  业务字段的配置

    业务字段判断标准:

    1、在搜索时是否需要在此字段上进行搜索。例如:商品名称、商品的卖点、商品的描述

    2、后续的业务是否需要用到此字段。例如:商品id。

    需要用到的字段:

    1、商品id

    2、商品title

    3、卖点

    4、价格

    5、商品图片

    6、商品分类名称

    7、商品描述

    Solr中的业务字段:

    1、id——》商品id

    其他的对应字段创建solr的字段。

    <field name="item_title" type="text_ik" indexed="true" stored="true"/>
    <field name="item_sell_point" type="text_ik" indexed="true" stored="true"/>
    <field name="item_price"  type="long" indexed="true" stored="true"/>
    <field name="item_image" type="string" indexed="false" stored="true" />
    <field name="item_category_name" type="string" indexed="true" stored="true" />
    <field name="item_desc" type="text_ik" indexed="true" stored="false" />
    
    <field name="item_keywords" type="text_ik" indexed="true" stored="false" multiValued="true"/>
    <copyField source="item_title" dest="item_keywords"/>
    <copyField source="item_sell_point" dest="item_keywords"/>
    <copyField source="item_category_name" dest="item_keywords"/>
    <copyField source="item_desc" dest="item_keywords"/>

    至此  solr的配置已经完成~

    有关solr 以及 IK Analyzer 的下载链接 http://pan.baidu.com/s/1i43DOW1 密码:u5gg

     

  • 相关阅读:
    Educational Codeforces Round 81 (Rated for Div. 2)(训练)
    Prime Path(POJ) 3126
    前端知识(一)04 Vue.js入门-谷粒学院
    前端知识(一)03 初识 ECMAScript 6-谷粒学院
    前端知识(一)02 初识 Node.js-谷粒学院
    前端知识(一)01 前端开发和前端开发工具-谷粒学院
    同步和异步、阻塞和非阻塞
    给HTML页面设置自己的icon
    解决MyBatis-Plus 3.3.1中自动生成代码tinyint(1)无法自动转换为Boolean 的办法
    驼峰命名和短横线命名的转换
  • 原文地址:https://www.cnblogs.com/mumudechengzhang/p/7707395.html
Copyright © 2020-2023  润新知