本文主要内容装载这里

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. VS Code

    VS Code VS Code(Visual Studio Code)是由微软研发的一款免费.开源的跨平台文本(代码)编辑器.几乎完美的编辑器. 官网:https://code.visualstudi ...

  2. Svn Patch 中文乱码

    关于Patch svn打patch的介绍:巧用svn create patch(打补丁)方案解决定制版需求 svn创建patch 1.在SVN的提交列表中,右键选择“创建补丁” 2.选择保存位置,保存 ...

  3. 搞netty

    开始搞netty了 查了下资料 在使用NIO 的时候,最好不要配置 SO_LINGER,假设设置了该參数,在 close的时候如缓冲区有数据待写出,会抛出 IOException. // 在netty ...

  4. 收集入侵Windows系统的证据

    随着网络的不断扩大,网络安全更加会成为人们的一个焦点,同时也成为是否能进一步投入到更深更广领域的一个基石.当然网络的安全也是一个动态的概念,世界上没有绝对安全的网络,只有相对安全的网络.相对安全环境的 ...

  5. luogu1003铺地毯[noip2011 提高组 Day1 T1]

    题目描述 为了准备一个独特的颁奖典礼,组织者在会场的一片矩形区域(可看做是平面直角坐标系的第一象限)铺上一些矩形地毯.一共有 n 张地毯,编号从 1 到n .现在将这些地毯按照编号从小到大的顺序平行于 ...

  6. http协议(五)web服务器

    1.http1.1规范允许一台http服务器搭建多个web站点... 比如提供web托管服务的供应商,可以用一台服务器为多为客户服务,也可以以每位客户持有的域名运行各自不同的网站,这里利用了虚拟服务器 ...

  7. cocoapod

    更新代码: sudo gem install -n /usr/local/bin cocoapods --pre ex: The dependency `` is not used in any co ...

  8. NodeJS 开篇 牛刀小试

    一.Node&NPM的安装与配置 下载:https://nodejs.org/en/ V4.2.x LTS(9.75MB)——长期支持版,成熟可靠 V5.x.x Stable(9.71MB)— ...

  9. Cordova - 使用Cordova开发iOS应用实战2(生命周期、使用Safari调试)

    Cordova - 使用Cordova开发iOS应用实战2(生命周期.使用Safari调试) 前文我们创建了一个简单的Cordova项目,结构如下: 1,Cordova生命周期事件 (1)device ...

  10. 线程本地变量ThreadLocal源码解读

      一.ThreadLocal基础知识 原始线程现状: 按照传统经验,如果某个对象是非线程安全的,在多线程环境下,对对象的访问必须采用synchronized进行线程同步.但是Spring中的各种模板 ...