商城系统开发从0到1(集成Lucene搜索商品信息)

在没有服务器资源部署ES的情况下,本文介绍如何使用Lucene作为临时替代方案进行商品信息搜索。虽然Lucene是ES的基础,但不支持集群部署,限制了其在生产环境的应用。文章详细阐述了从引入依赖、配置到接口实现的完整过程,并提出在商品管理操作时通过消息队列同步到搜索服务的解决方案。
摘要由CSDN通过智能技术生成

首先说明为什么现在还要用Lucene,用ES他不香吗!因为没有服务器资源,所以无法单独部署ES服务,只能先使用Lucene顶着先,因为ES是基于Lucene的,且是分布式的,后期有服务器后还是要换为ES,现在就让我们先用案例集成Lucene吧。

Lucene是apache软件基金会4 jakarta项目组的一个子项目,是一个开放源代码的全文检索引擎工具包,但它不是一个完整的全文检索引擎,而是一个全文检索引擎的架构,提供了完整的查询引擎和索引引擎,部分文本分析引擎(英文与德文两种西方语言)。

1.引入依赖

  <!--核心包-->
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-core</artifactId>
            <version>7.6.0</version>
        </dependency>
        <!--对分词索引查询解析-->
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-queryparser</artifactId>
            <version>7.6.0</version>
        </dependency>
        <!--一般分词器,适用于英文分词-->
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-analyzers-common</artifactId>
            <version>7.6.0</version>
        </dependency>
        <!--检索关键字高亮显示 -->
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-highlighter</artifactId>
            <version>7.6.0</version>
        </dependency>
        <!-- smartcn中文分词器 -->
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-analyzers-smartcn</artifactId>
            <version>7.6.0</version>
        </dependency>

2.配置LuceneConfig

@Configuration
public class LuceneConfig {

    @Autowired
    private  UEditorConfig uEditorConfig;
    /**
     * lucene索引,存放位置
     */
    private static final String LUCENEINDEXPATH="/lucene";
    /**
     * 创建一个 Analyzer 实例
     *
     * @return
     */
    //中文智能分词
//    @Bean
//    public Analyzer analyzer() {
//        return new SmartChineseAnalyzer(false);
//    }

    //类似于模糊搜索
    @Bean//(name = "analyzer")
    public Analyzer analyzer() {
        return new StandardAnalyzer();
    }

//    @Bean(name = "smartAnalyzer")
//    public Analyzer smartAnalyzer() {
//        return new SmartChine
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值