[lucene] 创建索引 Directory inderWriter
来源:互联网 发布:c语言培训费用 编辑:程序博客网 时间:2024/06/09 00:13
Lucene主要的类:
Directory 索引的位置 Document 的集合组成 是由 一般用来打开索引库 (结构倒排序的结构)
子类FSDirectory :
//创建索引目录 INDEX_PATH: 索引目录
Directory directory = FSDirectory.open(new File(INDEX_PATH));
Document 文档,lucene存储索引文件的形式,类似于DB中行,field 相当于DB中的列,
* 要写公共转化的方法:file转化成doc,doc 转化成file,类似于orm映射。
/**
* 转换内容对象为Document对象
* @param ct
* @return
*/
public static Document convertContentToDoc(ContentObject ct){
Document doc = new Document();
//Field.Store.YES 表示存储内容
doc.add(new StringField("title", ct.getTitle(), Field.Store.YES));
doc.add(new TextField("content", ct.getContent(),Field.Store.YES));
doc.add(new StringField("link", ct.getLink(), Field.Store.YES));
doc.add(new LongField("createDate",new Date().getTime(),Field.Store.YES));
return doc;
}
inderWriter 操作索引库的增删改查,添加doc 删除doc 查找doc 更改doc
构造方法:
IndexWriter(Directory?d,?IndexWriterConfig?conf) Constructs a new IndexWriter per the settings given in?conf.
IndexWriterConfig(Version?matchVersion,?Analyzer?analyzer)
Creates a new config that with defaults that match the specified?Version?as well as the default?Analyzer.
IndexWriterConfig indexWriterConfig = new IndexWriterConfig(version, analyzer);
indexWriterConfig.setMaxBufferedDocs(10000);
indexWriterConfig.setMergePolicy(mergePolicy);
indexWriterConfig.setRAMBufferSizeMB(50);
///设置索引的打开模式 创建或者添加索引
indexWriterConfig.setOpenMode(OpenMode.CREATE_OR_APPEND);
//如果索引文件被锁,解锁索引文件
if(IndexWriter.isLocked(directory)){
IndexWriter.unlock(directory);
}
Directory 索引的位置 Document 的集合组成 是由 一般用来打开索引库 (结构倒排序的结构)
子类FSDirectory :
//创建索引目录 INDEX_PATH: 索引目录
Directory directory = FSDirectory.open(new File(INDEX_PATH));
Document 文档,lucene存储索引文件的形式,类似于DB中行,field 相当于DB中的列,
* 要写公共转化的方法:file转化成doc,doc 转化成file,类似于orm映射。
/**
* 转换内容对象为Document对象
* @param ct
* @return
*/
public static Document convertContentToDoc(ContentObject ct){
Document doc = new Document();
//Field.Store.YES 表示存储内容
doc.add(new StringField("title", ct.getTitle(), Field.Store.YES));
doc.add(new TextField("content", ct.getContent(),Field.Store.YES));
doc.add(new StringField("link", ct.getLink(), Field.Store.YES));
doc.add(new LongField("createDate",new Date().getTime(),Field.Store.YES));
return doc;
}
inderWriter 操作索引库的增删改查,添加doc 删除doc 查找doc 更改doc
构造方法:
IndexWriter(Directory?d,?IndexWriterConfig?conf) Constructs a new IndexWriter per the settings given in?conf.
IndexWriterConfig(Version?matchVersion,?Analyzer?analyzer)
Creates a new config that with defaults that match the specified?Version?as well as the default?Analyzer.
IndexWriterConfig indexWriterConfig = new IndexWriterConfig(version, analyzer);
indexWriterConfig.setMaxBufferedDocs(10000);
indexWriterConfig.setMergePolicy(mergePolicy);
indexWriterConfig.setRAMBufferSizeMB(50);
///设置索引的打开模式 创建或者添加索引
indexWriterConfig.setOpenMode(OpenMode.CREATE_OR_APPEND);
//如果索引文件被锁,解锁索引文件
if(IndexWriter.isLocked(directory)){
IndexWriter.unlock(directory);
}
0 0
- [lucene] 创建索引 Directory inderWriter
- lucene学习----创建索引
- lucene创建索引
- Java_ABC_3.Lucene创建索引
- Lucene 索引创建
- LUCENE创建索引【鸡蛋】
- Lucene 索引创建
- lucene--创建索引,搜索
- lucene创建索引
- Lucene 4.4 创建索引
- Lucene.Net创建索引
- lucene 索引创建查询
- Lucene 索引创建 .
- lucene创建索引
- lucene 创建索引
- Lucene之创建索引
- Lucene创建空索引
- Lucene-索引创建&搜索
- Android应用中对于微信分享的实例及问题
- Sql Server 2008数据库的导出与备份
- Android Adapter优化
- andriod驱动之旅-在Ubuntu为Android硬件抽象层(HAL)模块编写JNI方法提供Java访问硬件服务接口(6)
- 自加自减
- [lucene] 创建索引 Directory inderWriter
- ffmpeg使用NDK r9编译
- C++ primer plus 6th ed. 中文版读书笔记【第二章】
- 通过proc文件系统输出必要的Linux内核信息(上)
- Rotate Image
- 从PL/SQL FAQ中摘抄出来几篇比较有用的文章
- 内核笔记:内核线程的创建
- python学习笔记--3
- web架构 之 Nginx负载均衡