个人开源项目smart_search_box

recommend

smart_search_box是java领域的一站式搜索引擎解决方案,用户只需要进行简单的配置就可以在项目中引入完整的全文搜索能力,包括数据入库自动索引,搜索词联想,热词提示,高亮等功能。同时提供给用户高度的自定义能力,用户可以替换框架的部分实现,包括替换elastic search客户端,替换分词器,替换redis客户端等,只需要实现对应的接口替换默认注入的相应组件即可。默认使用smart_elk_client作为elk客户端,使用ansj作为中文分词器,使用jedis作为redis客户端。

qucick start

1 clone项目
由于smart_search_box对于个人的另外一个开源项目smart_elk_client有依赖,所以需要clone两个项目。

git clone git@github.com:Tinysakura/smart_elk_client.git
git clone git@github.com:Tinysakura/smart_search_box.git

2 maven编译
注意两个项目都要编译一下

mvn clean install -Dmaven.test.skip=true

3 在项目pom中引入

<dependency>
   <groupId>com.tinysakura</groupId>
   <artifactId>smart-search-box</artifactId>
   <version>0.0.1-RELEASE</version>
</dependency>

usage

1 配置项

# 在指定包下扫描@Document注解与@Field注解<必选>
smart_search_box.annotation.document.scan.package=com.tinysakura.smartsearchbox.entity

# 在指定包下扫描@Index注解<必选>
smart_search_box.annotation.index.scan.package=com.tinysakura.smartsearchbox.dao

# 索引高亮查询前置标签<可选>
smart_search_box.index_query.highlight.pre_tags=<b>

# 索引高亮查询后置标签<可选>
smart_search_box.index_query.highlight.post_tags=</b>

# 默认使用的分析器<可选>
smart_search_box.index_query.default_analyzer=ik_smart

# 被索引的文档对应的实体类,不同类之间使用,分隔<必选>
smart_search_box.index_query.document_classes=com.tinysakura.smartsearchbox.entity.Book

# 是否异步索引文档<必选>
smart_search_box.document_index.async=false

# 搜索提示结果中对应用户行为的比例<必选>
smart_search_box.search_prompt.behavior.ratio=0.2

# 搜索提示结果中对应文档的比例<必选>
smart_search_box.search_prompt.document.ratio=0.8

# 指定用于存储搜索提示的zset容量<必选>
smart_search_box.search_prompt.zset.capacity=10

# 指定用于存储搜索提示的zset缓冲区域容量(即zset的总容量为capacity + cache_capacity)<必选>
smart_search_box.search_prompt.zset.cache_capacity=20

# 搜索提示敏感词<todo>
smart_search_box.search_prompt.sensitive_word=violence,pornographic

# 指定搜索提示高亮部分前置标签<可选>
smart_search_box.search_prompt.highlight.pre_tags=<b>

# 指定搜索提示高亮部分后置标签<可选>
smart_search_box.search_prompt.highlight.post_tags=</b>

# 清理用户行为对应的zset的间隔(单位毫秒)<必选>
smart_search_box.search_prompt.behavior_zset.clean_up_interval=1800000

# 初始化索引使用的线程池大小<必选>
smart_search_box.index_init.thread_pool.size=3

# 索引文档使用的线程池大小<必选>
smart_search_box.document_index.thread_pool.size=3

# 默认使用jedis作为redis java客户端
jedis.pool.host=127.0.0.1
jedis.pool.port=6379
jedis.pool.config.maxTotal=100 
jedis.pool.config.maxIdle=10
jedis.pool.config.maxWaitMill=100000

# elk节点
elk.node.ip=http://127.0.0.1:9200

如果要使用框架提供的默认的组件快速开始,请务必按照如上的配置项进行配置。如果需要使用自定义的redis和elk客户端请根据实际情况进行redis和elk相关配置,只需要保证对应的接口实现可以正确完整的提供相应服务即可。

2 配置spring扫描框架的配置包

@SpringBootApplication(scanBasePackages = {
   "com.tinysakura.smartsearchbox.config")

3 使用注解
框架主要提供三个注解,@Document, @Field, @Index,下面分别介绍这三个注解

@Document
该注解用来配置索引基本属性与搜索提示相关配置,请在数据库表对应的实体类上使用该注解,注解有如下选项

@Target({
   ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Document {
   
    /**
     * 指定索引名
     * @return
     */
    public String indexName();

    /**
     * 指定文档类型
     * @return
     */
    public String documentType() default "";

    /**
     * 指定搜索提示字段
     * @return
     */
    public String[] searchPromptFields() default "";

    /**
     * 指定分片数量
     * @return
     */
    public int shardsNumber() default 4;

    /**
     * 指定索引副本数量
     * @return
     */
    public int replicasNumber() default 1;

    /**
     * 是否开启动态类型猜测
     * @return
     */
    public boolean dynamic() default true;

    /**
     * 是否使用_all字段
     * @return
     */
    public boolean extraAll() default true;

    /**
     * 是否启用_size字段
     * @return
     */
    public boolean extraSize() default false;

    /**
     * 是否启用_timestamp字段
     * @return
     */
    public boolean extraTimestamp()<
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值