Lucene4.7.2 FieldCache获取值

//获取Int

FieldCache.Ints ints = FieldCache.DEFAULT.getInts(AtomicReader reader, String field, boolean setDocsWithField);

//获取docId的域值

int value = ints.get(docId);

//获取string

BytesRef bytesRef = new BytesRef(); 
BinaryDocValues terms = FieldCache.DEFAULT.getTerms(AtomicReader reader, String field, boolean setDocsWithField);
terms.get(doc,bytesRef);
String value = bytesRef.utf8ToString();

Lucene 4.10.0

BinaryDocValues terms = getTerms(AtomicReader reader, String field, boolean setDocsWithField);
String value = terms.get(docId).utf8ToString();

//基于FieldCache的Filter

Filter f = FieldCacheRangeFilter.newIntRange("left", 0, 100, true, true);
Filter filter = new FieldCacheTermsFilter("type", new BytesRef[]{new BytesRef("science"), new BytesRef("it")});


注意的地方:

1. fieldCache中的字段值是从倒排表中读出来的,而不是从索引文件中存储的字段值,所以排序的字段必须设为索引字段
2 .用来排序的字段在索引的时候不能拆分(tokenized),因为fieldCache数组中,每个文档只对应一个字段值,拆分的话,cache中只会保存在词典中靠后的值。
3 .fieldcache是lucene最占用的内存的部分,大部分内存溢出的错误都是由它而起,需要特别注意。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值