1.maven项目pom.xml加入依赖

<dependency>

<groupId>org.hibernate</groupId>

<artifactId>hibernate-search-orm</artifactId>

<version>5.5.0.Final</version>

</dependency>

<dependency>

<groupId>org.apache.lucene</groupId>

<artifactId>lucene-queryparser</artifactId>

<version>5.3.0</version>

</dependency>

<!--中文分词器>

<dependency>

<groupId>org.apache.lucene</groupId>

<artifactId>lucene-analyzers-smartcn</artifactId>

<version>5.3.0</version>

</dependency>

2.在application.xml中添加配置

<property name="hibernateProperties">
<props>
//文件系统
<prop key="hibernate.search.default.directory_provider">filesystem</prop>
//索引存储目录
<prop key="hibernate.search.default.indexBase">e:/index</prop>
</props>
</property>

3.domain(bean)中实体类配置

类上注解

注释@Indexed将实体类标记为需要通过Hibernate Search进行索引的实体。

注释@Analyzer(impl=SmartChineseAnalyzer.class),我配置了中文分词器,默认是StandardAnalyzer.calss

类中属性注解

Hibernate Search需要将实体标识符存储在每个实体的索引中。默认情况下,它将使用标记为@Id的字段,但您可以使用@DocumentId(仅限高级用户)覆盖此字段。

注释@Field用于实体类属性上,其中参数的默认值为index = Index.YES,analyze = Analyze.YES和store = Store.NO。

Lucene索引主要是基于字符串的,还有一些额外的数字类型支持。有关更多详情,请参阅Bridges。

关联实体的索引

@IndexedEmbedded注释用于索引关联实体,如通常通过@ManyToMany,@OneToOne,@ManyToOne,@Embedded和@ElementCollection定义的实体,有关详细信息,请参阅嵌入式和关联对象。

4.注解实体类例子

@Entity
@Table(name = "t_task")
@Indexed
@Analyzer(impl=SmartChineseAnalyzer.class)
public class Task {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@DocumentId
private Long id; @Column(name="c_taskname")
@Field
private String taskName;//任务名称
@Column(name="c_address")
private String address;//工作地点
@Column(name = "c_content")
@Field
private String content;// 任务内容

5.全文检索索引初始化

  /*全文搜索索引初始化*/
public void initFullTextIndex() throws Exception{
FullTextSession fullTextSession = Search.getFullTextSession(currentSession());
fullTextSession.createIndexer().startAndWait();
}

6.全文检索查询

/*全文搜索*/
public List fullTextSearch(){
FullTextSession fullTextSession = Search.getFullTextSession(currentSession());
Transaction tx = fullTextSession.beginTransaction();
QueryBuilder qb = fullTextSession.getSearchFactory() .buildQueryBuilder().forEntity(entityType).get();
org.apache.lucene.search.Query query = qb .keyword() .onFields("taskName", "content") .matching("扫黄") .createQuery();
org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(query, entityType);
List result = hibQuery.list();
return result;
}

[SpringBoot系列]--Spring Hibernate search 注解实现(未测试)的更多相关文章

  1. SpringBoot系列-整合Mybatis(注解方式)

    目录 一.常用注解说明 二.实战 三.测试 四.注意事项 上一篇文章<SpringBoot系列-整合Mybatis(XML配置方式)>介绍了XML配置方式整合的过程,本文介绍下Spring ...

  2. 零基础学习java------40---------Maven(maven的概念,安装,maven在eclipse中使用),springboot(spring整合springmvc(注解),spring整合mybatis(常见的配置文件)),前端页面(bootstrap软件)

    一 maven 1. Maven的相关概念 1.1 项目开发中遇到的问题 (1)都是同样的代码,为什么在我的机器上可以编译执行,而在他的机器上就不行? (2)为什么在我的机器上可以正常打包,而配置管理 ...

  3. SpringBoot系列: Spring项目异常处理最佳实践

    ===================================自定义异常类===================================稍具规模的项目, 一般都要自定义一组异常类, 这 ...

  4. SpringBoot系列: Spring支持的异常处理方式

    ===================================视图函数返回 status code 的方式===================================Spring 有 ...

  5. SpringBoot系列: Spring MVC视图方法的补充

    SpringMVC 视图方法的参数, 已经在这个文章中写得非常清楚了, 链接为 https://www.cnblogs.com/morethink/p/8028664.html 这篇文章做一些补充. ...

  6. [转载]SpringBoot系列: SpringMVC 参数绑定注解解析

    本文转载自 https://www.cnblogs.com/morethink/p/8028664.html, 作者写得非常好, 致谢! SpringMVC 参数绑定注解解析   本文介绍了用于参数绑 ...

  7. SpringBoot系列: RestTemplate 快速入门

    ====================================相关的文章====================================SpringBoot系列: 与Spring R ...

  8. spring boot 学习(三)API注解记录及测试

    spring boot API注解记录及测试 部分注解解析 @Controller : 修饰创建处理 http 处理对象,一般用于页面渲染时使用. @RestController : Json数据交互 ...

  9. Springboot 系列(十)使用 Spring data jpa 访问数据库

    前言 Springboot data jpa 和 Spring jdbc 同属于 Spring开源组织,在 Spring jdbc 之后又开发了持久层框架,很明显 Spring data jpa 相对 ...

随机推荐

  1. WPF判断当前窗体是否为模态

    WPF判断当前窗体是否为模态   1.使用System.Windows.Interop.ComponentDispatcher.IsThreadModal来判断 参照:https://social.m ...

  2. ASP.NET Core URL Rewrite中间件

    URL重写是基于一个或多个预置规则修改请求URL的行为.URL重写在资源位置和访问地址之间创建了一种抽象,这样二者之间就减少了紧密的联系.URL重写有多种适用的场景: 临时或永久移动或替换服务器资源, ...

  3. 谈谈iOS开发如何写个人中心这类页面--静态tableView页面的编写

    本文来自 网易云社区 . 一.本文讲的是什么问题? 在开发 iOS 应用时,基本都会遇到个人中心.设置.详情信息等页面,这里截取了某应用的详情编辑页面和个人中心页面,如下: 我们以页面结构的角度考虑这 ...

  4. Delphi32位程序拷贝system32目录中文件解决方法!

    源码下载:http://download.csdn.net/detail/sunylat/9740352 unit Unit1; interface uses Winapi.Windows, Wina ...

  5. NOI2017 酱油记

    侥幸混进市队让我晚退役了几个月..不过终究还是退役了呢..这应该是最后一篇游记了吧.. 考前半个月都在安徽集训..然后发现所有人都停课集训..只有我暑假了开始.. 反正上课各种听不懂..各种被大佬虐. ...

  6. win10环境下搭建虚拟环境和 virtualenvwrapper-win 使用

    1. 安装 virtualenv pip install virtualenv 2. virtualenv基本操作 cd path/dir # 跳转到dir目录 virtualenv env # 在d ...

  7. Postman使用手册4——API test

    一.Pre Request Scripts Postman v0.10+ 版本支持pre-request scripts. prerequest script.png pre-request scri ...

  8. [集合]Collection集合框架源码分析

    Collection接口 在java的集合类库中,基本接口是Collection,该接口的在集合中的源码定义如下(将源码中的注释删掉了): public interface Collection< ...

  9. JavaScript的深拷贝和浅拷贝

    一.数据类型 数据分为基本数据类型(String, Number, Boolean, Null, Undefined,Symbol)和对象数据类型.. 1.基本数据类型的特点:直接存储在栈(stack ...

  10. 制作kvm镜像、格式转换

    2018-12-25 制作kvm镜像(以centos 7 为例) 执行创建虚拟机命令 virt-install --name centos7_kvm --memory --vcpus= --disk ...