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. }  
  • 相关阅读:
    codeforces 368B
    codeforces 651A
    codeforces 651B
    codeforces 732B
    codeforces 313B
    codeforces 550A
    codeforces 498B
    Linux C/C++基础——内存分区
    Linux C/C++基础——变量作用域
    Linux C/C++基础——Windows远程登录Linux
  • 原文地址:https://www.cnblogs.com/lexus/p/2291603.html
Copyright © 2011-2022 走看看