zoukankan      html  css  js  c++  java
  • 如何让Document.getFieldable 返回 NumericField

    [lucene] 如何让Document.getFieldable 返回 NumericField

    pufan 2010-07-26
    看java doc知道,NumericField只能在index时使用,Document.getFieldable 返回的是Field而不是NumericField。

    目前的需求要能够返回NumericField,哪怕是修改源码也可以。对lucene底层不熟,我看了看实现没有任何头绪,哪位达人给点思路吧,不吝感谢。
    viruscamp 2010-08-06
    Java代码  收藏代码
    1. //建立  
    2. long dt = new Date().getTime()  
    3. document.add(new NumericField("date",Field.Store.YES,true).setLongValue(dt));  
    4.   
    5. //读取  
    6. long dt = Long.parseLong(doc.get("date"));  
    7. datestr = timeformat.format(new Date(dt));  
    pufan 2010-08-11
    感谢楼上的回复,其实我要求的是自动转换(某些情况下并不清楚某个field是什么类型):
    Java代码  收藏代码
    1. //建立     
    2. long dt = new Date().getTime()     
    3. document.add(new NumericField("date",Field.Store.YES,true).setLongValue(dt));     
    4.     
    5. //读取     
    6. Fieldable f=doc.getFieldable("date");  
    7. if(f instanceof NumericField )  
    8. {  
    9.    NumericField nf=(NumericField )f;     
    10.   Long date=(Long)nf.getNumericValue();  
    11.   datestr = timeformat.format(new Date(date));  
    12. }  
    13. else  
    14. {  
    15.   ...  
    16. }  
  • 相关阅读:
    rsync用法详细解释
    配置本地yum仓库
    电脑硬件知识
    LVM逻辑卷管理
    前端文本截断
    程序员编写技术文档的新手指南
    JavaScript 是世界上最好的语言?
    一天只工作 3 小时的程序员,已坚持两年
    数据库水平切分方法
    MySQL 笔记整理(1) --基础架构,一条SQL查询语句如何执行
  • 原文地址:https://www.cnblogs.com/lexus/p/2291603.html
Copyright © 2011-2022 走看看