歡迎您光臨本站 註冊首頁

lucene plus 2.1 發布,簡化搜索

←手機掃碼閱讀     admin @ 2019-09-02 , reply:0

去除lucene繁瑣的操作,讓你專註於實現業務!

文檔

簡介:https://gitee.com/Myzhang/luceneplus/blob/master/README.md

javadoc:https://apidoc.gitee.com/Myzhang/luceneplus

Demo:https://gitee.com/Myzhang/luceneplus/tree/master/src/test/java/com/ld/lucenex/demo

特點

  • 原生lucene用法

  • 天然支持多數據源

  • 自帶數據源創建和垃圾回收

  • 默認實現近實時索引

  • MyDocument 加持 支持 map、json、obj 自動轉換

  • 一鍵高亮支持

  • 統一的service介面思想

  • 註解式聲明欄位

入門

創建lucene數據源

new LuceneX(new LuceneXConfig() {
            @Override
            public void configLuceneX(BaseConfig me) {
                me.add("d:/","test",Empty.class);
            }
        });

定義實體類

import com.ld.lucenex.field.FieldKey;
import com.ld.lucenex.field.LDType;

public class Empty{

    @FieldKey(type = LDType.IntPoint)
    private int id;
    @FieldKey(type = LDType.StringField)
    private String name;
    @FieldKey(type = LDType.TextField,highlight = true)
    private String text;

    public int getId() {
        return id;
    }

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

    public String getName() {
        return name;
    }

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

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }
}

添加索引

Listempties = new ArrayList<>(10);
        for (int i=0;i<10;i++){
            Empty empty = new Empty();
            empty.setId(i);
            empty.setName("新聞");
            empty.setText("8月29日,2019世界人工智慧大會在上海開幕,本屆大會以「智聯世界,無限可能」為主題,展示包括中國在內各國最新的AI產品和技術。在本屆大會上,除了各國展出的最新AI技術和產品外,由華為、寒武紀、依圖等國內企業自主研發的人工智慧晶元組成的AI晶元牆更是受到參觀者的關注。圖為微軟帶來了智能菜品識別系統,把食物放在收銀檢測區,便能自覺識別價格。更厲害的是,系統還能給出營養分析報告,例如熱量、脂肪、碳水物、蛋白質等含量。");
            empties.add(empty);
        }
        ServiceImplbasisService = ServiceFactory.getService(ServiceImpl.class);
        basisService.addObjects(empties);

查詢索引

ServiceImplbasisService = ServiceFactory.getService(ServiceImpl.class);
        Empty searchOne = basisService.searchOne(new TermQuery(new Term("name","百度一下")));

高亮顯示條件

  • 欄位表明 highlight = true,並且 type = LDType.TextField

@FieldKey(type = LDType.TextField,highlight = true)
    private String text;
  • 必須調用searchList 並且返回類型是

實時索引條件

  • 必須調用ServiceImpl內置的添加/更新刪除方法

如何自定義 Service 查詢介面

import com.ld.lucenex.service.ServiceImpl;

public class DemoServiceextends ServiceImpl{
    public DemoService(String sourceKey) {
        super(sourceKey);
    }
}

如何與其他web/非web框架集成

  • 只要在項目啟動的時候 創建lucene數據源即可

更新日誌

v2.1

  • 去除一個遞歸調用介面bug


[admin ]

來源:OsChina
連結:https://www.oschina.net/news/109539/luceneplus-2-1-released
lucene plus 2.1 發布,簡化搜索已經有281次圍觀

http://coctec.com/news/soft/show-post-213557.html