国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

A simple example about full-text search based Java:Lucene

2019-11-18 15:03:40
字體:
來源:轉載
供稿:網友

  索引源代碼:
package lUCene;

/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author Shirley
* @version 1.0
*/

import org.apache.lucene.index.*;
import org.apache.lucene.analysis.*;
import java.io.*;
import org.apache.lucene.document.*;

public class IndexFiles {
  //使用方法:: IndexFiles [索引輸出目錄] [索引的文件列表] ...
  public static void main(String[] arg) throws Exception {
    String[] args = new String[2];
    //索引后存放索引信息的路徑
    args[0] = System.getPRoperty("java.io.tmpdir", "tmp") + System.getProperty("file.separator") + "index-1";
    //待索引文件
    args[1] = "E://AppWork//lucene//rfc2047.txt";
    args[2] = "E://AppWork//cyberOffice//CO//Sheldon Java Mail.htm";
    args[3] = "E://AppWork//lucene//englishtest.doc";
    args[4] = "E://AppWork//cyberoffice//CO//xls1.xls";
    args[5] = "E://AppWork//cyberoffice//CO//PPT1.ppt";

    String indeXPath = args[0];
    IndexWriter writer;
    //用指定的語言分析器構造一個新的寫索引器(第3個參數表示是否為追加索引)
    writer = new IndexWriter(indexPath, new SimpleAnalyzer(), false);

    for (int i=1; i<args.length; i++) {
      System.out.println("Indexing file " + args[i]);
      InputStream is = new FileInputStream(args[i]);

      //構造包含2個字段Field的Document對象
      //一個是路徑path字段,不索引,只存儲
      //一個是內容body字段,進行全文索引,并存儲
      Document doc = new Document();
      doc.add(Field.UnIndexed("path", args[i]));
      doc.add(Field.Text("body", (Reader) new InputStreamReader(is)));
      //將文檔寫入索引


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 云和县| 湖北省| 卫辉市| 和顺县| 栾城县| 保康县| 全州县| 丰县| 商水县| 太原市| 鄱阳县| 大关县| 峡江县| 漾濞| 凤山县| 临夏县| 嵩明县| 门源| 昭觉县| 枞阳县| 富民县| 盖州市| 明星| 东山县| 汉川市| 阿克陶县| 南阳市| 万盛区| 海原县| 丰台区| 司法| 雷山县| 洪湖市| 贵溪市| 桐柏县| 佛教| 扶沟县| 怀化市| 和静县| 皮山县| 华亭县|