Lucene五(新增日期和數字型別索引)

2021-07-04 00:04:37 字數 1361 閱讀 1519

日期和數字型別索引可以使用numericfield物件來新增,建立索引、搜尋、測試的**如下:

public class indexutil ;

private string emails = ;

private string contents = ;

private date dates = null;

private int attachs = ;

private string names = ;

//用於存放加權資訊

private mapscores = new hashmap();

private directory directory = null;

public indexutil() catch (ioexception e)

}private void setdates() catch (parseexception e)

}/**

* 建立索引

*/public void index() else

writer.adddocument(doc);

}} catch (corruptindexexception e) catch (lockobtainfailedexception e) catch (ioexception e) finally catch (corruptindexexception e) catch (ioexception e) }}

public void search()

reader.close();

} catch (corruptindexexception e) catch (ioexception e) }

單元測試:

@test

public void testindex()

@test

public void testsearch()

執行testindex後再執行testsearch的結果如下:

(5-1.0-0.84584934)jake[[email protected]]-->6,5,1305734400000

(0-1.0-0.634387)zhangsan[[email protected]]-->1,2,1266508800000

(1-1.0-0.634387)lisi[[email protected]]-->2,3,1326211200000

(4-1.0-0.5981058)mike[[email protected]]-->5,5,1325347200000

(3-1.0-0.21146233)jetty[[email protected]]-->4,4,1292947200000

(2-1.0-0.15859675)john[[email protected]]-->3,1,1316361600000

6 學習Lucene3 5之對日期和數字進行索引

為數字和日期建立索引 numericfield string name,int precisionstep,store store,boolean index 為這兩項建立索引有專門的方法,numericfield 其中第四個引數不再是索引的方式,而是是否進行索引 為數字建立索引 numericfi...

mysql 日期轉換和數字格式轉換

時間轉成年月日時分秒 select date format now y m d h i s 時間轉成年月日 select date format now y m d 去年此時 select date add now interval 1 year 上月此時 select date add now i...

5 時間日期和數字

date類 格式化規則 dateformat dateformat y yy 兩位的年份,yyyy為四位的年份 m mm 兩位的月份,mmm為漢字月份 d dd 兩位日期 h hh 兩位小時 m mm 兩位分數 s ss 兩位秒 e 字串輸出星期 calendar類 主要配個date計算。calen...