利用springboot,mybatis和luncene整合创建博客系统(只给出全数据库搜索并显示在搜索页面)

本文介绍了如何使用SpringBoot、Mybatis框架与Lucene整合,搭建一个包含全数据库搜索功能的博客系统。通过添加Lucene依赖、创建实体类等步骤,实现了关键词高亮显示的搜索效果。
摘要由CSDN通过智能技术生成

这几天搭建一个博客系统,利用的springboot、mybatis框架搭建了一下并整合了luncene全数据库检索,定时器功能。其他不说了,看下如何整合luncene吧

1.在pom.xml中添加全文检索的jar包


      <!--  lucnene核心包 -->
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-core</artifactId>
            <version>5.5.0</version>
        </dependency>
        <!-- lucnene解析包 -->
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-queryparser</artifactId>
            <version>5.5.0</version>
        </dependency>
        <!--  lucene 公共包分析器 -->
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-analyzers-common</artifactId>
            <version>5.5.0</version>
        </dependency>
        <!--  中文分词 -->
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-analyzers-smartcn</artifactId>
            <version>5.5.0</version>
        </dependency>
        <!--  关键词高亮显示 -->
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-highlighter</artifactId>
            <version>5.5.0</version>
        </dependency>



2.创建实体类

package com.wchstrife.entity.common;

import org.apache.lucene.store.Directory;

/**
 * 创建中文索引类
 * Created by T430 on 2017/8/18.
 */
public class Indexer {

    private  Integer ids[];//主键ID
    private  String titles[];//标题
    private  String contents[];//内容
    private Directory dir;//字典




    public Integer[] getIds() {

        return ids;
    }

    public void setIds(Integer[] ids) {
        this.ids = ids;
    }

    public String[] getTitles() {
        return titles;
    }

    public void setTitles(String[] titles) {
        this.titles = titles;
    }

    public String[] getContents() {
        return contents;
    }

    public void setContents(String[] contents) {
        this.contents = contents;
    }

    public Directory getDir() {
        return dir;
    }

    public void setDir(Directory dir) {
        this.dir = dir;
    }
}

3,创建service层

package com.wchstrife.service;

import com.wchstrife.entity.article;
import com.wchstrife.entity.common.Indexer;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.store.Directory;

import java.io.IOException;
import java.util.List;

/**
 * 索引Service
 * Created by T430 on 2017/8/18.
 */
public interface IndexService {


    Indexer getIndexer();

    Ind
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值