003-基础使用之-如何启动和使用-跟我学全文检索之原生态lucenex

源码地址 欢迎star

qq群:475349334

欢迎加入开发

上篇已经把如何配置lucenex 都已经说完了、是不是感觉很简单、那么接下来 给大家聊聊他怎么启动

一行代码、简单暴力、把你继承LuceneXConfig的类直接扔进来即可

LuceneX.start(DemoConfig.class);

既然启动完了那就看看怎么用了、这就要提一下 BasisService  这个类呢,继承了底层Service 实现了 常用的一些CURD

这里简单列出来一点、还有的我就不一一列出了

public void addIndex(List<?> list) //添加索引 集合可以是java Object 和 Map 自动转换为 Document
public List<Document> searchList(Query query, int n) //简单的集合查询
public <T> Page<Document> searchList(Query query,Page<Document> page)//简单的分页查询
public List<Document> searchTotal()//简单的查询全部
public long addDocuments(Iterable<? extends Iterable<? extends IndexableField>> docs)//简单添加
public long addDocument(Iterable<? extends IndexableField> doc)
public int count(Query query)
public Document getDocument(int docID)
public TopDocs search(Query query, int n)
public TopFieldDocs search(Query query, int n, Sort sort)

如果自带的这些方法足够用了,那么直接 new 一个 BasisService 使用即可《必须在启动之后》参数为 dataKey

new BasisService("test")

如果需要自己扩展,那么请继承 BasisService 实现 一个无参构造方法和有参构造方法《必须》

然后就可以在自定义方法里使用 父类的方法和IndexWriter和IndexSearcher 当然了 如果需要使用基础配置信息也是可以的

SourceConfig和Constants  这都是在 LuceneXConfig里面配置的 并且 每个源的SourceConfig是不一样的

扫描二维码关注公众号,回复: 1656061 查看本文章

这里简单举例:

new BasisService("test").deleteAll();

如果简单的使用就完了、如果那里不会和不懂请加QQ群交流

猜你喜欢

转载自blog.csdn.net/a1324705312/article/details/80480626