Lucene3.6.2包介绍,第一个Lucene案例介绍,查看索引信息的工具lukeall介绍,Luke查看的索引库内容,索引查找过程
.embody{
padding:10px 10px 10px;
margin:0 -20px;
border-bottom:solid 1px #ededed;
}
.embody_b{
margin:0 ;
padding:10px 0;
}
.embody .embody_t,.embody .embody_c{
display: inline-block;
margin-right:10px;
}
.embody_t{
font-size: 12px;
color:#999;
}
.embody_c{
font-size: 12px;
}
.embody_c img,.embody_c em{
display: inline-block;
vertical-align: middle;
}
.embody_c img{
width:30px;
height:30px;
}
.embody_c em{
margin: 0 20px 0 10px;
color:#333;
font-style: normal;
}
分类:
爬虫(8)


版权声明:本文为博主原创文章,未经博主允许不得转载。
1 Lucen目录介绍
2
lucene-core-3.6.2.jar是lucene开发核心jar包
contrib 目录存放,包含一些扩展jar包
3
案例
建立第一个Lucene项目:lucene3_day1
(1)需要先将数据转换成为Document对象,每一个数据信息转换成为Field(String
name, String value, Field.Store store, Field.Indexindex)
(2)指定索引库位置Directorydirectory = FSDirectory.open(new
File("index"));// 当前Index目录
(3)分词器Analyzeranalyzer =
new StandardAnalyzer(Version.LUCENE_36);
(4)写入索引:
|
IndexWriterConfig indexWriterConfig = Version.LUCENE_36, analyzer); IndexWriter indexWriter = //将document数据写入索引库 indexWriter.addDocument(document); //关闭索引 indexWriter.close(); |
案例编写:
|
案例目录: |
|
Article.java |
|
package cn.toto.lucene.quickstart; public private private String private String /** * @return the */ public return } /** * @param id */ public this.id } /** * @return the */ public String getTitle() { return } /** * @param title */ public this.title } /** * @return the */ public String getContent() { return } /** * @param content */ public this.content } } |
|
package cn.toto.lucene.quickstart; import java.io.File; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.Field.Index; import org.apache.lucene.document.Field.Store; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.util.Version; import org.junit.Test; /** * * * * * */ public @Test public Article article = new Article(); article.setId(100); article.setTitle("Lucene快速入门"); article.setContent("Lucene是提供了一个简单却强大的应用程式接口," + "能够做全文检索索引和搜寻,在Java开发环境里Lucene是" "一个成熟的免费的开放源代码工具。"); // Document document = new Document(); document.add(new Field("id", article.getId() + "", Store.YES, Index.ANALYZED )); document.add(new Field("title", document.add(new Field("content", // // Directory directory = FSDirectory.open(new // Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_36); // IndexWriterConfig indexWriterConfig = new IndexWriterConfig( Version.LUCENE_36, analyzer); IndexWriter indexWriter = new IndexWriter(directory, // indexWriter.addDocument(document); // indexWriter.close(); } } |
|
运行单元测试后的结果: 运行后index目录下的结果: |
4
可以通过luke工具查看索引库中内容(它是一个jar包)
下载网址:http://code.google.com/p/luke/
打开方式:
如果用这种方式打不可以,可以用命令的方式打开文件,进入这个目录,选中Shift+鼠标右键—>此处打开命令窗口—>输入命令:java
-jar lukeall-3.5.0.jar
工具的截图如下:
点击OK后的结果:
通过overview可以查看到索引信息,通过Document可以查看文档对象信息
5
查找
|
和上面的并集的query代码如下: |
|
@Test public { //建立Query对象--根据标题 String queryString = "Lucene"; //第一个参数,版本号 //第二个参数,字段 //第三个参数,分词器 Analyzer analyzer = new QueryParser queryParser = new QueryParser(Version.LUCENE_36,"title",analyzer); Query query = queryParser.parse(queryString); //根据Query查找 // Directory directory = FSDirectory.open(new IndexSearcher indexSearcher = new IndexSearcher(IndexReader.open(directory)); //条数据 TopDocs topDocs = indexSearcher.search(query, 100); System.out.println("满足结果记录条数:" //获取结果 ScoreDoc[] scoreDocs = topDocs.scoreDocs; for (int //先获得Document下标 int docID = scoreDocs[i].doc; Document document = indexSearcher.doc(docID); System.out.println("id:" System.out.println("title:" System.out.println("content:" } indexSearcher.close(); } |
|
运行结果: |
Luke查看的索引库内容:
索引库中信息,包括两大部分:
A
索引词条信息
B
文档对象信息
每个Field中都存在一个Store和一个Index
索引内容和Document内容有什么关系
查找时,通过索引内容
查找
文档对象信息
索引的查找过程
- 顶
- 0
- 踩
- 0
Lucene3.6.2包介绍,第一个Lucene案例介绍,查看索引信息的工具lukeall介绍,Luke查看的索引库内容,索引查找过程的更多相关文章
- 2.Lucene3.6.2包介绍,第一个Lucene案例介绍,查看索引信息的工具lukeall介绍,Luke查看的索引库内容,索引查找过程
1 Lucen目录介绍 2 lucene-core-3.6.2.jar是lucene开发核心jar包 contrib 目录存放,包含一些扩展jar包 3 案例 建立第一个Lucene项目 ...
- top命令查看线程信息和jstack使用介绍
top -Hp pid可以查看某个进程的线程信息 -H 显示线程信息,-p指定pid jstack 线程ID 可以查看某个线程的堆栈情况,特别对于hung挂死的线程,可以使用选项-F强制打印dump信 ...
- 一个简单好用的zabbix告警信息发送工具
之前使用邮件和短信发送zabbix告警信息,但告警信息无法实时查看或者无法发送,故障无法及时通知运维人员. 后来使用第三方微信接口发送信息,愉快地用了一年多,突然收费了. zabbix告警一直是我的痛 ...
- [置顶]
一个简单好用的zabbix告警信息发送工具
之前使用邮件和短信发送zabbix告警信息,但告警信息无法实时查看或者无法发送,故障无法及时通知运维人员. 后来使用第三方微信接口发送信息,愉快地用了一年多,突然收费了. zabbix告警一直是我的痛 ...
- lucene 全文检索工具的介绍
Lucene:全文检索工具:这是一种思想,使用的是C语言写出来的 1.Lucene就是apache下的一个全文检索工具,一堆的jar包,我们可以使用lucene做一个谷歌和百度一样的搜索引擎系统 2. ...
- Lucene介绍及简单入门案例(集成ik分词器)
介绍 Lucene是apache软件基金会4 jakarta项目组的一个子项目,是一个开放源代码的全文检索引擎工具包,但它不是一个完整的全文检索引擎,而是一个全文检索引擎的架构,提供了完整的查询引擎和 ...
- 第一个lucene程序,把一个信息写入到索引库中、根据关键词把对象从索引库中提取出来、lucene读写过程分析
新建一个Java Project :LuceneTest 准备lucene的jar包,要加入的jar包至少有: 1)lucene-core-3.1.0.jar (核心包) 2) lucene- ...
- Dubbo入门介绍---搭建一个最简单的Demo框架
Dubbo入门---搭建一个最简单的Demo框架 置顶 2017年04月17日 19:10:44 是Guava不是瓜娃 阅读数:320947 标签: dubbozookeeper 更多 个人分类: D ...
- Fiddler抓包工具详细介绍
本文转自:http://www.cnblogs.com/Chilam007/p/6985379.html 一.Fiddler与其他抓包工具的区别 1.Firebug虽然可以抓包,但是对于分析http请 ...
随机推荐
- UVA1583-Digit Generator(紫书例题3.5)
For a positive integer N , the digit-sum of N is defined as the sum of N itself and its digits. When ...
- JSp获取到当前用户的全部session
<%@page import="java.util.Enumeration"%> <% for (Enumeration<?> e = session ...
- Git学习总结(10)——git 常用命令汇总
1.git 基本概念: 工作区:改动(增删文件和内容) 暂存区:输入命令:git add 改动的文件名,此次改动就放到了'暂存区'(新增的文件) 本地仓库(简称:本地):输入命令:git commit ...
- android启动第一个界面时即闪屏的核心代码(两种方式)
闪屏,就是SplashScreen,也能够说是启动画面,就是启动的时候,闪(展示)一下,持续数秒后.自己主动关闭. 第一种方式: android的实现很easy,使用Handler对象的postDe ...
- CSS3可伸缩框属性,可用于等分显示子元素或按比例显示子元素的大小
使用方法跟Android的android:layout_weight属性类似.可类比Android中的使用方法.这样比較好记,因为眼下全部浏览器都不支持大部分的属性,所以全部的属性都须要加上Firef ...
- android init进程分析 init脚本解析和处理
(懒人近期想起我还有csdn好久没打理了.这个android init躺在我的草稿箱中快5年了.略微改改发出来吧) RC文件格式 rc文件是linux中常见的启动载入阶段运行的文件.rc是run co ...
- UVA 1016 - Silly Sort 置换分解 贪心
Silly Sort Your younger brother has an assignment and needs s ...
- vuejs2.0 文档
http://vuejs.org/ vuejs2.0 英文文档 https://vuefe.cn/ vuejs2.0 中文文档
- [jzoj 5926] [NOIP2018模拟10.25] naive 的图 解题报告(kruskal重构树+二维数点)
题目链接: https://jzoj.net/senior/#main/show/5926 题目: 题解: 显然最小的最大路径在最小生成树上(最小生成树=最小瓶颈生成树) 于是我们建出kruskal重 ...
- Linux命令详解./configure,make,make install的作用
这些都是典型的使用GNU的AUTOCONF和AUTOMAKE产生的程序的安装步骤. ./configure是用来检测你的安装平台的目标特征的.比如它会检测你是不是有CC或GCC,并不是需要CC或GCC ...