您的位置:首页 > 数据库

lucene全文检索与数据库检索的区别

2016-03-30 20:41 337 查看
1.性能

数据库:like检索(会把表中数据进行一行一行的扫描,)性能慢

Lucene检索:先把数据那过来建立检索,然后在根据建立的索引进行查找,这样的话我们需要多维护一份索引表。多一个创建索引的过程,但是我们是一次创建多次使用。

2:相关度排序

数据库检索:通过 order by 关键字来操作。

Lucene检索:对查询出来的每个document都有一个算法,(得分)得分是根据算法算出来的。得分越高,排序的顺序越靠前。

排序可以人工干预(通过设置权重值)

代码:

public static Document articleToDocument(Article article){

Document document=new Document();

IntField idfield=new IntField("id",article.getId(),Store.YES);

StringField authorfield=new StringField("author", article.getAuthor(), Store.YES);

StringField urlfield=new StringField("link", article.getLink(), Store.YES);

TextField title=new TextField("title", article.getTitle(),Store.YES);

//设置权重值,默认为1f..

title.setBoost(4f);


TextField contentfield=new TextField("content", article.getContent(),Store.YES);

document.add(idfield);

document.add(authorfield);

document.add(urlfield);

document.add(title);

document.add(contentfield);

return document;

}

3:匹配的准确度

数据库检索: 通过like 关键字进行检索 其中相关文字得用 % 来表示 如:like %ant%

Lucene检索:先把数据拿过来分词建立索引,根据建好的索引进行查找。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: