乙個Lucene例子

2022-05-02 22:06:11 字數 814 閱讀 9276

public

void

test1()

;  //迴圈陣列,建立文件,給文件新增字段,並把文件新增到索引書寫器裡

document doc 

=null

;  for(

inti =0

; i 

<

words.length; i++)

//索引優化

ramwriter.optimize();

//關閉索引讀寫器,一定要關哦,按理說應該把上面的**用try括主,在finally裡關閉索引書寫器

ramwriter.close();

//構建乙個索引搜尋器

indexsearcher searcher 

=new

indexsearcher(ramdir);

//用queryparser.parse方法例項化乙個查詢

query query 

=queryparser.parse("人民

", "contents", 

newchineseanalyzer());

//獲取搜尋結果

hits hits 

=searcher.search(query);

//判斷是否有搜尋到的結果,當然你也可以遍歷結果集並輸出

//if (hits.length() != 0)

"有");

//else

"沒有");

for(

inti =0

; i 

<

hits.length(); i++)

}

乙個lucene搜尋高亮顯示的例子。

above,create documents with two fields,one with term vectors tv and one without notv indexsearcher searcher new indexsearcher directory queryparser pa...

lucene的一簡單例子

1.引入lucene包,用到了junit,包搞進來就可以了 2.先跑建立索引檔案的單元測試,有了索引才能查詢嘛,然後在跑下面的檢索資料方法 3.目錄根據自己需要更改哦 private final string indexpath e lucene private final string searc...

乙個cmd ftpscript 例子

乙個例子,每日自動更新norton病毒庫的 bat檔案 dir e software symantec viruslib sy exe pause ftp s cescript.txt rem e software symantec viruslib symcdefsx86.exe q copy e...