你好,游客 登录 注册 搜索
背景:
阅读新闻

初识Lucene 4.5全文搜索

[日期:2014-07-22] 来源:Linux社区  作者:linhongyu [字体: ]

近期想研究下lucene,但网络上的教程大多都是lucne 3.x版本的讲解。可是lucene版本的更新速度快的惊人,目前已经到了4.8版了,只好去查阅官方文档。虽然英文不大好,但稍微对比了下发现3.x版本至4.x版本的修改非常之大。接下来我就以4.5版来操作,分享下我对luence的初步认识。

先给大家看一张图(来至《Lucene  in  action》http://www.linuxidc.com/Linux/2013-10/91052.htm):

初识Lucene 4.5全文搜索

此图很形象的描述了lucene的基本流程,简而言之就是:1、创建索引;2、检索索引。

--------------------------------------分割线 --------------------------------------

基于Lucene多索引进行索引和搜索 http://www.linuxidc.com/Linux/2012-05/59757.htm

Lucene 实战(第2版) 中文版 配套源代码 http://www.linuxidc.com/Linux/2013-10/91055.htm

Lucene 实战(第2版) PDF高清中文版 http://www.linuxidc.com/Linux/2013-10/91052.htm

使用Lucene-Spatial实现集成地理位置的全文检索 http://www.linuxidc.com/Linux/2012-02/53117.htm

Lucene + Hadoop 分布式搜索运行框架 Nut 1.0a9 http://www.linuxidc.com/Linux/2012-02/53113.htm

Lucene + Hadoop 分布式搜索运行框架 Nut 1.0a8 http://www.linuxidc.com/Linux/2012-02/53111.htm

Lucene + Hadoop 分布式搜索运行框架 Nut 1.0a7 http://www.linuxidc.com/Linux/2012-02/53110.htm

Project 2-1: 配置Lucene, 建立WEB查询系统[Ubuntu 10.10] http://www.linuxidc.com/Linux/2010-11/30103.htm

--------------------------------------分割线 --------------------------------------

太深的道理与原理我目前也还是一知半解,所以就以小白的思维来阐述。

Lucene与数据库有许多相通之处,以下我们做个简单对比:

 
数据库
Luecene
基本概念
/字段
Field
/记录
Document
基本操作
查询(SELECT)
Searcher
添加(INSERT)

IndexWriter. addDocument

删除(DELETE)
IndexReader.delete
修改(UPDATE)
不支持(可删除后重新添加)

上面的表格式某位网友博文里的对比,我觉得挺好理解的。可以这么去认为吧,lucene把你数据库里的数据做了个索引,以后你要全文查找某数据时就可以从索引中查找,就好比字典的索引目录!

废话说了一大堆,还是用代码来说话,首先要往代码里导入三个包:

lucene-analyzers-common-4.5.0、lucene-core-4.5.0、lucene-queryparser-4.5.0

要有面向对象的思维嘛,先创建一个javabean:luceneBeans,用来存放你所要的数据


package pojo;

public class LuceneBeans {

private String id;

private String title;

private String introduce;

private String addtime;

private String category;

public LuceneBeans() {

super();

}

public LuceneBeans(String id, String title, String introduce,

String addtime, String category) {

super();

this.id = id;

this.title = title;

this.introduce = introduce;

this.addtime = addtime;

this.category = category;

}

public String getId() {

return id;

}

public void setId(String id) {

this.id = id;

}

public String getTitle() {

return title;

}

public void setTitle(String title) {

this.title = title;

}

public String getIntroduce() {

return introduce;

}

public void setIntroduce(String introduce) {

this.introduce = introduce;

}

public String getAddtime() {

return addtime;

}

public void setAddtime(String addtime) {

this.addtime = addtime;

}

public String getCategory() {

return category;

}

public void setCategory(String category) {

this.category = category;

}

}

更多详情见请继续阅读下一页的精彩内容http://www.linuxidc.com/Linux/2014-07/104532p2.htm

linux
相关资讯       Lucene  Lucene 4.5  Lucene全文搜索 
本文评论   查看全部评论 (0)
表情: 表情 姓名: ��数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款