lucene以及solr作为索引工具已经被广泛使用,以前项目中也有用到过lucene4.x,如今lucene版本已经到5.1了,再次了解一下,来写个demo!

首先附一下文档及下载地址:

a:下载地址 Lucene下载

b:文档地址 lucene API

所需jar包(只附lucene相关jar):

  • lucene-analyzers-common-5.1.0.jar
  • lucene-core-5.1.0.jar
  • lucene-queries-5.1.0.jar
  • lucene-queryparser-5.1.0.jar

 

索引的创建

我们这里先讲一下索引的创建,官方已经给出了一个demo的代码,我们这边模拟一下实际开发中的demo,模拟一下需求 如下

1,首先,索引的建立分为两个部分,a:直接重新建立,b:在原有基础上更新部分索引

2,通过定时器在一定时间内更新索引,或者重建索引(当然如果需要也可增加人工点击操作)

3,索引的一些配置信心应当存放于配置文件中,方便修改

首先,假设需要查询一个产品相关的信息,定义一下po

package com.demo.test;

import java.util.Date;

public class Product {
    private String id;
    private String name;
    private String keywords;
    private String description;
    private String sn;
    private Date updatedTime;

    public Product() {
        super();
    }

    public Product(String id, String name, String keywords, String description,
            String sn) {
        super();
        this.id = id;
        this.name = name;
        this.keywords = keywords;
        this.description = description;
        this.sn = sn;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getKeywords() {
        return keywords;
    }

    public void setKeywords(String keywords) {
        this.keywords = keywords;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getSn() {
        return sn;
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    public Date getUpdatedTime() {
        return updatedTime;
    }

    public void setUpdatedTime(Date updatedTime) {
        this.updatedTime = updatedTime;
    }

}
Product.java

相关文章:

  • 2021-06-01
  • 2021-12-15
  • 2021-11-23
  • 2021-10-12
  • 2018-04-04
  • 2021-09-28
  • 2021-10-12
  • 2021-11-06
猜你喜欢
  • 2021-09-10
  • 2021-11-20
  • 2020-02-25
  • 2021-08-31
  • 2021-08-31
  • 2019-02-12
  • 2021-09-10
  • 2021-11-29
相关资源
相似解决方案