2022年Lucene总体图_建索引_查询_数据库索引 .pdf
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《2022年Lucene总体图_建索引_查询_数据库索引 .pdf》由会员分享,可在线阅读,更多相关《2022年Lucene总体图_建索引_查询_数据库索引 .pdf(7页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、总体图3.0 版本的结构和之前的版本(2.9 之前)相比,在程序结构上表现出来就只是多了一个message 包,用来专门处理国际化。见上图,可以看到,3.0 和之前的版本一样还是由对外接口、索引核心以及基础结构封装三大部分共八个模块(也即包package) ,详细介绍详见附件一。我们从上图也可以看到Lucene 搜索时的调用关系:当我们要查询一个词时,在查询模块(search)会先调用语法分析器(queryParser)对查询语句进行分析,语法分析模块调用了词法分析器( analysis)进行词法分析,如对搜索关键字分词、过滤等,词法分析器在使用时会根据实际情况调用国际化模块( message
2、)进行一些国际化的处理。当这些前置工作做完之后,才真正进入到搜索核心,首先会调用索引模块(index),它负责向底层的存储类(store)去读取索引文件里面的数据,然后返回给查询模块。其他模块在整个搜索过程中是作为公共类存在的。附件一、Lucnen3.0 包详细介绍1、analysis Analysis 包含一些内建的分析器,例如按空白字符分词的WhitespaceAnalyzer ,添加了stopwrod 过滤的 StopAnalyzer,最常用的是StandardAnalyzer。2、document Document 包含文档的数据结构,例如Document 类定义了存储文档的数据结构,
3、Field 类定义了 Document 的一个域。3、index Index 包含了索引的读写类,例如对索引文件的segment 进行写、合并、优化的IndexWriter 类 和 对 索 引 进 行 读 取 和 删 除 操 作 的IndexReader 类 , 这 里 要 注 意 的 是 不 要 被IndexReader 这个名字误导,以为它是索引文件的读取类,实际上删除索引也是由它完成,IndexWriter 只关心如何将索引写入一个个segment,并将它们合并优化;IndexReader 则关注索引文件中各个文档的组织形式。4、queryParser 名师资料总结 - - -精品资料欢
4、迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 7 页 - - - - - - - - - QueryParser 包含了解析查询语句的类,lucene 的查询语句和sql 语句有点类似,有各种保留字,按照一定的语法可以组成各种查询。Lucene 有很多种Query 类,它们都继承自Query,执行各种特殊的查询,QueryParser 的作用就是解析查询语句,按顺序调用各种Query 类查找出结果。5、search Search 包含了从索引中搜索结果的各种类,例如刚才说的各种Query 类,包括Ter
5、mQuery、BooleanQuery 等就在这个包里。6、store Store 包含了索引的存储类,例如Directory定义了索引文件的存储结构,FSDirectory 为存储在文件中的索引,RAMDirectory 为存储在内存中的索引,MmapDirectory 为使用内存映射的索引。7、util Util 包含一些公共工具类,例如时间和字符串之间的转换工具。8、message 处理国际化的类。- Lucene3.0 学习笔记1(建立索引)默认分类2010-04-25 19:45:52 阅读 136 评论 1 字号:大中小订阅我们首先在d:lucenes 下放置了几个txt 文件作为
6、索引的源。创建d:luceneindex 作为索引文件的存放地址。当然还需要引入lucene3.0 的包。具体步骤简介如下:1、创建 Directory 对象(参数是存放索引的File 类型,根据File 的存放地点选择创建类)2、创建 indexWriter 对象,参数(Directory 对象,分词器,是否创建,分词的最大值)3、获取源文件的File 数组4、通过循环将每个文件写入索引。 创建 Document 对象,并创建Field 对象(列名称(文件名、内容等) ,将Field 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - -
7、 - 名师精心整理 - - - - - - - 第 2 页,共 7 页 - - - - - - - - - 加入到 Dcument 中,通过IndexWriter.addDocument(Document) 写入索引中。 5、关闭 indexWriter 。源码:CODE=java package com.hector.firstlucene; /* * * author Hector * 建立索引lucene3.0 */ import java.io.File; import java.io.FileReader; import java.io.IOException; import jav
8、a.util.Date; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.DateTools; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.store.Directory; import org
9、.apache.lucene.store.SimpleFSDirectory; import org.apache.lucene.util.Version; public class TextFileIndexer /* * param args * throws IOException */ public static void main(String args) throws IOException / 保存索引文件的地方String indexDir = “ d:index ” ; / 将要搜索TXT文件的地方String dateDir = “ d:s” ; IndexWriter i
10、ndexWriter = null; / 创建Directory 对象,FSDirectory 代表待索引的文件存在磁盘上Directory dir = new SimpleFSDirectory(new File(indexDir); / 创建 IndexWriter 对象 ,第一个参数是Directory,第二个是分词器,第三个表示是否是创建 ,如果为false 为在此基础上面修改,第四表示表示分词的最大值,比如说 new MaxFieldLength(2) ,就表示两个字一分,一般用IndexWriter.MaxFieldLength.LIMITED indexWriter = new
11、IndexWriter(dir,new 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 7 页 - - - - - - - - - StandardAnalyzer(Version.LUCENE_30),true,IndexWriter.MaxFieldLength.U NLIMITED); File files = new File(dateDir).listFiles(); for (int i = 0; i files.length; i+) Document do
12、c = new Document(); / 创建Field 对象,并放入doc 对象中doc.add(new Field(“ contents” , new FileReader(files*i+); doc.add(new Field(“ filename” , files*i+.getName(), Field.Store.YES, Field.Index.NOT_ANALYZED); doc.add(new Field(“ indexDate” ,DateTools.dateToString(new Date(), DateTools.Resolution.DAY),Field.Stor
13、e.YES,Field.Index.NOT_ANALYZED); / 写入IndexWriter indexWriter.addDocument(doc); / 查看IndexWriter 里面有多少个索引System.out.println(“ numDocs” +indexWriter.numDocs(); indexWriter.close(); Lucene3.0 学习笔记2(查询索引)默认分类2010-04-25 19:46:47 阅读 312 评论2 字号:大中小订阅转自 :http:/ d:luceneindex 是上一篇学习笔记(Lucene3.0 学习笔记1(建立索引) )中
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年Lucene总体图_建索引_查询_数据库索引 2022 Lucene 总体 索引 查询 数据库
![提示](https://www.deliwenku.com/images/bang_tan.gif)
限制150内