lucene-Field.Store解析
本文主要内容装载这里
Store 三种形态
COMPRESS:压缩保存。用于长文本或二进制数据 (后期高版本舍弃了)
YES:保存
NO:不保存
具体案例
package demo.first; import java.io.IOException; 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.CorruptIndexException;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.store.LockObtainFailedException; public class TestFieldStore {
/**
* 索引文件的存放位置
*/
String path = "D://workspace//fwk//lucenedemo//firstLuceneIndex"; public void createLuceneIndex(){
try {
IndexWriter iw = new IndexWriter(path,new StandardAnalyzer(),true);
Document doc = new Document();
//Store.YES 保存 可以查询 可以打印内容
Field storeYes = new Field("storeyes","storeyes",Store.YES,Index.TOKENIZED);
//Store.NO 不保存 可以查询 不可打印内容 由于不保存内容所以节省空间
Field storeNo = new Field("storeno","storeno",Store.NO,Index.TOKENIZED);
//Store.COMPRESS 压缩保存 可以查询 可以打印内容 可以节省生成索引文件的空间 Field storeCompress = new Field("storecompress","storecompress",Store.COMPRESS,Index.TOKENIZED);
doc.add(storeYes);
doc.add(storeNo);
doc.add(storeCompress);
iw.addDocument(doc);
iw.optimize();
iw.close();
} catch (CorruptIndexException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (LockObtainFailedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} public void testSearch(){
try {
IndexSearcher iser = new IndexSearcher(path); /*
* Store.YES 采用保存模式,可以查询到,并且可以打印出内容
*/
System.out.println("---storeYes");
QueryParser queryParser1 = new QueryParser("storeyes",new StandardAnalyzer());
Hits hits1 = iser.search(queryParser1.parse("storeyes"));
for(int i = 0;i<hits1.length();i++){
System.out.println("id :"+hits1.id(i));
System.out.println("doc :"+hits1.doc(i));
System.out.println("context :"+hits1.doc(i).get("storeyes"));
System.out.println("score :"+hits1.score(i));
} /*
* Store.NO 采用不保存模式,可以查询到,但是不能打印出内容
*/
System.out.println("---storeNo");
QueryParser queryParser2 = new QueryParser("storeno",new StandardAnalyzer());
Hits hits2 = iser.search(queryParser2.parse("storeno"));
for(int i = 0;i<hits2.length();i++){
System.out.println("id :"+hits2.id(i));
System.out.println("doc :"+hits2.doc(i));
System.out.println("context :"+hits2.doc(i).get("storeno"));
System.out.println("score :"+hits2.score(i));
} /*
* Store.COMPRESS 采用压缩保存模式,可以查询到,并且可以打印出内容
*/
System.out.println("---storeCompress");
QueryParser queryParser3 = new QueryParser("storecompress",new StandardAnalyzer());
Hits hits3 = iser.search(queryParser3.parse("storecompress"));
for(int i = 0;i<hits3.length();i++){
System.out.println("id :"+hits3.id(i));
System.out.println("doc :"+hits3.doc(i));
System.out.println("context :"+hits3.doc(i).get("storecompress"));
System.out.println("score :"+hits3.score(i));
} iser.close();
} catch (CorruptIndexException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} public static void main(String[] args) {
TestFieldStore tfs = new TestFieldStore();
tfs.createLuceneIndex();
tfs.testSearch();
}
}
由此可以看出Field.Store的设置与否与是否可以搜索到无关。
这里整理一下
Field.Store
:YES 可以搜索,保存原值
:NO 可以搜索,不保存原值
:COMPRESS 可以搜索,压缩保存原值
这里需要注意的是在实际使用中,并不建议使用COMPRESS,存在压缩和解压过程,效率低下,对于大文本尽量使用NO
还有一点就是是否可被搜索与Store无关,只与Index有关。
这里使用的是lucene 2.3.2
lucene-Field.Store解析的更多相关文章
- Lucene——Field.Store(存储域选项)及Field.Index(索引选项)
Field.Store.YES或者NO(存储域选项) 设置为YES表示或把这个域中的内容完全存储到文件中,方便进行文本的还原 设置为NO表示把这个域的内容不存储到文件中,但是可以被索引,此时内容无法完 ...
- lucene中Field.Index,Field.Store详解
lucene在doc.add(new Field("content",curArt.getContent(),Field.Store.NO,Field.Index.TOKENIZE ...
- 【转载】lucene中Field.Index,Field.Store详解
lucene在doc.add(new Field("content",curArt.getContent(),Field.Store.NO,Field.Index.TOKENIZE ...
- lucene中Field.Index,Field.Store的一些设置
lucene在doc.add(new Field("content",curArt.getContent(),Field.Store.NO,Field.Index.TOKENIZE ...
- Lucene.NET中Field.Index 和 Field.Store的几种属性的用法
转载自 http://blog.csdn.net/yja886/article/details/6612069 lucene在doc.add(new Field("content" ...
- Lucene Field
org.apache.lucene.demo.IndexFiles类中,使用递归的方式去索引文件.在构造了一个IndexWriter索引器之后,就可以向索引器中添加Doucument了,执行真正地建立 ...
- Lucene 全文搜索解析
一.创建查询对象的方式 对要搜索的信息创建 Query 查询对象,Lucene 会根据 Query 查询对象生成最终的查询语法.类似关系数据库 Sql 语法一样,Lucene 也有自己的查询语法,比如 ...
- Lucene学习总结之七:Lucene搜索过程解析
一.Lucene搜索过程总论 搜索的过程总的来说就是将词典及倒排表信息从索引中读出来,根据用户输入的查询语句合并倒排表,得到结果文档集并对文档进行打分的过程. 其可用如下图示: 总共包括以下几个过程: ...
- (三)Lucene——Field域和索引的增删改
1. Field域 1.1 Field的属性 是否分词(Tokenized) 是:对该field存储的内容进行分词,分词的目的,就是为了索引. 比如:商品名称.商品描述.商品价格 否:不 ...
随机推荐
- HOLOLENS如何调节屏幕亮度和音量?
圆环左边的两个是亮度按键,右边的是两个音量按键,值得注意的是,无论是两个音量键还是亮度键,它们都被设置成了一凸一凹,凸的按键为音量/亮度+键,凹为-键,其工业设计可见一斑.
- 配置WebSite的IIS时遇到的问题与解决方法
http://www.cnblogs.com/mingmingruyuedlut/archive/2011/11/04/2235630.html#commentform
- java 27 - 7 反射之 通过反射越过泛型检查
之前学过的集合里面都有泛型,规定了泛型的类型以后,就不能往这个集合添加除了这个类型之外的类型数据了. 那么,有什么方法可以越过这个泛型,添加特定类型以外的类型数据么? 例子: 往ArrayList& ...
- LFI漏洞利用总结
主要涉及到的函数 include(),require().include_once(),require_once() magic_quotes_gpc().allow_url_fopen().allo ...
- centos7 安装拼音输入法(转载)
http://m.blog.csdn.net/article/details?id=52137523
- Java的super调用案例: super.getClass()返回的是子类自己
If you override a method from your superclass (or your superclass's superclass etc.), super.theMetho ...
- Anterior and posterior commissures
Source: https://en.wikipedia.org/wiki/Posterior_commissure Figrues archive.
- usb驱动开发17之设备生命线
拜会完了山头的几位大哥,还记得我们从哪里来要到哪里去吗?时刻不能忘记自身的使命啊.我们是从usb_submit_urb()最后的那个遗留问题usb_hcd_submit_urb()函数一路走来,现在就 ...
- 探索Windows 8.1 Update 新功能点
Windows 8.1 Update 已经使用一段时间了,整体感觉比Windows 8.1 方便了不少,尤其是对鼠标用户来说更是进行了很多优化. 应用磁贴尺寸 在应用磁贴点击鼠标右键,有小.中.宽.大 ...
- eap
本文介绍了eap