LucenePlus基于 Lucene 的全文搜索框架
lucenex 原LucenePlus
基于JDK 1.8 & lucene 7.x 的搜索框架、在不影響原本性能的同時(shí)、提升80%的開發(fā)效率、降低70%的開發(fā)難度?。?!
更新日志
v1.0
*去除第三方分詞依賴&無用的Jar *使用cglib 動(dòng)態(tài)代理創(chuàng)建 Service *新增攔截器 *添加更新 默認(rèn)異步
特點(diǎn)
原聲Lucene 用法
注解式聲明字段
多庫自動(dòng)切換
自動(dòng)管理資源創(chuàng)建于釋放
自動(dòng)高性能近實(shí)時(shí)索引
可持續(xù)擴(kuò)展的Service 接口設(shè)計(jì)
內(nèi)置常用的 增刪改查
可直接添加Java對(duì)象與Map集合 無需手動(dòng)創(chuàng)建 Document
支持操作回退
可自定義分詞器
默認(rèn)異步提交和更新
用法
1、繼承 LuceneXConfig
public class DemoConfig extends LuceneXConfig{
@Override
public void configConstant(Constants me) {
}
@Override
public void configLuceneX(BaseConfig me) {
// 存儲(chǔ)目錄 、名稱、高亮、分詞器、存儲(chǔ)類
me.add("d:/", "test", false, new PerFieldAnalyzerWrapper(new StandardAnalyzer()), Empty.class);
}
}
2、獲取Service
//默認(rèn)使用第一個(gè)存儲(chǔ)庫(如果您只有一個(gè)庫或使用第一個(gè)庫的話) BasisService basisService = LdService.newInstance(BasisService.class); //自定義使用庫 BasisService basisService = LdService.newInstance(BasisService.class,"test");
3、內(nèi)置基礎(chǔ)方法 滿足一般業(yè)務(wù)
public ListTermQuery(String field,String value,int num) public long IntDelete(String field,int value) public void addIndex(List> list) public List searchList(Query query, int n) public Page searchList(Query query,Page page) public List searchTotal() public long addDocuments(Iterable extends Iterable extends IndexableField>> docs) public long addDocument(Iterable extends IndexableField> doc) public int count(Query query) public TopDocs search(Query query, int n) public TopFieldDocs search(Query query, int n, Sort sort) public long deleteAll() public long deleteDocuments public long deleteDocuments(Term... terms) public void deleteUnusedFiles() public long updateIndex(List list,Term term) public List toDocument(List> list) public void goBack()
4、如何測(cè)試
//手動(dòng)啟動(dòng) LuceneX.start(DemoConfig.class);
5、如何實(shí)現(xiàn)自己的Service
5.1、繼承BasisService
5.2、可以使用父類已有的基礎(chǔ)方法也可以使用 SourceConfig config 變量獲取以下字段
private String indexPath;//存儲(chǔ)地址 private boolean highlight;//是否高亮 private IndexWriter writer;//寫入對(duì)象 private IndexSearcher searcher;//查詢對(duì)象 private PerFieldAnalyzerWrapper analyzer;//分詞器 private Class> defaultClass;//存儲(chǔ)對(duì)象Class private Highlighter highlighter;//高亮標(biāo)簽
5.3、使用實(shí)例Demo
default public int count(Query query) throws IOException {
return config.getSearcher().count(query);
}評(píng)論
圖片
表情
