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. C#设计模式系列:代理模式(Proxy Pattren)

    一.引言 在软件开发过程中,有些对象有时候会由于网络或者其他的障碍,以至于不能够或者不能直接访问到这些对象,如果直接访问对象给系统带来不必要的复杂性,这时候可以在客户端和目标对象之间增加一层中间层,让 ...

  2. Nginx使用

    1. 基本使用 分linux和windows版 windows版可以直接双击exe运行,默认配置为80端口,只有两个页面 html目录下为页面.css.js等代码文件 conf目录下为配置文件 主要的 ...

  3. MySQL不带where条件的UPDATE和DELETE 限制操作说明

    本文来自 网易云社区 . 数据安全是业务的基石,但是DBA 总会遇到救火情况,业务误删除全表或者误更新错全表业务数据,导致服务不可用 sql_safe_updates参数可以限制不带where条件的u ...

  4. BZOJ1901 Dynamic Rankings|带修主席树

    题目链接:戳我 其实我并不会做,于是看了题解 我们都知道主席树是利用前缀和记录历史版本来搞区间K大的一种数据结构.不过一般的主席树只能搞定静态区间第K大.如果带修怎么办呢? 想一下...单点修改+区间 ...

  5. ItemContainerStyleSelector

    ItemContainerStyleSelector是容器Style选择器 用法和ItemTemplateSelector差不多 同样也是也是继承类 StyleSelector,也是重写方法Selec ...

  6. leetcode 39 组合总和 JAVA

    题目: 给定一个无重复元素的数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合. candidates 中的数字可以无限制 ...

  7. DatagridView 控件列顺序与设置的不一样

    解决方案如下 : 1. dataGridView1.AutoGenerateColumns = false; 2. 绑定的dataSource 中所有的列都要写进去(列一定是绑定的模型中属性) 先在界 ...

  8. Blocks to Cubes

    Bholu the Pandit on this New Year wanted to divide his Cuboidal Packaging block into cubes. But he l ...

  9. kvm虚拟机静态迁移

    1.静态迁移就是虚拟机在关机状态下,拷贝虚拟机虚拟磁盘文件与配置文件到目标虚拟主机中,实现的迁移. (1)虚拟主机各自使用本地存储存放虚拟机磁盘文件 本文实现基于本地磁盘存储虚拟机磁盘文件的迁移方式, ...

  10. [Maven实战-许晓斌]-[第三章] Mave使用入门二(在IDE中的使用) [第四章] 案例的背景介绍

    创建maven项目