本文主要内容装载这里

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解析的更多相关文章

  1. Lucene——Field.Store(存储域选项)及Field.Index(索引选项)

    Field.Store.YES或者NO(存储域选项) 设置为YES表示或把这个域中的内容完全存储到文件中,方便进行文本的还原 设置为NO表示把这个域的内容不存储到文件中,但是可以被索引,此时内容无法完 ...

  2. lucene中Field.Index,Field.Store详解

    lucene在doc.add(new Field("content",curArt.getContent(),Field.Store.NO,Field.Index.TOKENIZE ...

  3. 【转载】lucene中Field.Index,Field.Store详解

    lucene在doc.add(new Field("content",curArt.getContent(),Field.Store.NO,Field.Index.TOKENIZE ...

  4. lucene中Field.Index,Field.Store的一些设置

    lucene在doc.add(new Field("content",curArt.getContent(),Field.Store.NO,Field.Index.TOKENIZE ...

  5. Lucene.NET中Field.Index 和 Field.Store的几种属性的用法

    转载自 http://blog.csdn.net/yja886/article/details/6612069 lucene在doc.add(new Field("content" ...

  6. Lucene Field

    org.apache.lucene.demo.IndexFiles类中,使用递归的方式去索引文件.在构造了一个IndexWriter索引器之后,就可以向索引器中添加Doucument了,执行真正地建立 ...

  7. Lucene 全文搜索解析

    一.创建查询对象的方式 对要搜索的信息创建 Query 查询对象,Lucene 会根据 Query 查询对象生成最终的查询语法.类似关系数据库 Sql 语法一样,Lucene 也有自己的查询语法,比如 ...

  8. Lucene学习总结之七:Lucene搜索过程解析

    一.Lucene搜索过程总论 搜索的过程总的来说就是将词典及倒排表信息从索引中读出来,根据用户输入的查询语句合并倒排表,得到结果文档集并对文档进行打分的过程. 其可用如下图示: 总共包括以下几个过程: ...

  9. (三)Lucene——Field域和索引的增删改

          1. Field域 1.1  Field的属性 是否分词(Tokenized) 是:对该field存储的内容进行分词,分词的目的,就是为了索引. 比如:商品名称.商品描述.商品价格 否:不 ...

随机推荐

  1. java 27 - 7 反射之 通过反射越过泛型检查

    之前学过的集合里面都有泛型,规定了泛型的类型以后,就不能往这个集合添加除了这个类型之外的类型数据了. 那么,有什么方法可以越过这个泛型,添加特定类型以外的类型数据么? 例子:  往ArrayList& ...

  2. 如何查看文件是dos格式还是unix格式的?

    一.背景 由于windows和linux对换行的标识不一样,不同系统的代码传递导致代码格式的改变中可能会带来程序无法正常编译通过的问题.因此根据一些编译的错误提示,可以定位到是文件格式的问题,要对程序 ...

  3. NSIS来自己设定快捷方式的图标

    CreateShortCut 快捷文件.lnk 目标文件 参数 图标文件 图标索引号 启动选项 键盘快捷键 描述 CreateShortCut "$DESKTOP\快捷方式.lnk" ...

  4. Kubernetes deployed on multiple ubuntu nodes

    This document describes how to deploy kubernetes on multiple ubuntu nodes, including 1 master node a ...

  5. 040医疗项目-模块四:采购单模块—采购单创建好之后跳转到采购单修改页面(editcgd.action)

    我们上一篇文章写到了要从editcgd.action为入口讲.我们要做的事根据edicgd.acion进入到Action层的一个函数,在这个函数里面要做的就是从数据库中把采购单表里面的数据都查出来显示 ...

  6. 利用javascript对提交数据验证

    优点:提交前验证.在客户端进行. <html> <head> <script language="javascript"> function c ...

  7. Incorrect string value异常解决

    mysql数据库的一个问题 1366-Incorrect string value:'\xE5\x8D\xA1\xE5......' for column 'filename' at row 1 问题 ...

  8. Theano2.1.21-基础知识之theano中多核的支持

    来自:http://deeplearning.net/software/theano/tutorial/multi_cores.html Multi cores support in Theano 一 ...

  9. 你应该知道的25道Javascript面试题

    题目来自 25 Essential JavaScript Interview Questions.闲来无事,正好切一下. 一 What is a potential pitfall with usin ...

  10. 对《重建中国.NET生态系统》评论贴的总结

    Neuzilla官方微信公众号:搜 架构师联盟 或 neuzilla,也可以扫下面二维码 在看了<重建中国.NET生态系统>的各种哭爹喊娘骂街的评论之后,我觉得哦,淫才确实很多,但是么真正 ...