欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
用Lucene建立索引及查詢(xún)示例
(http://www.chinaitpower.com/A200507/2005-07-27/170086.html)   
作者:未知 時(shí)間:2005-07-27 22:19 出處:CSDN 責編:chinaitpower     
              摘要:用Lucene建立索引及查詢(xún)示例     

首先去 apache 網(wǎng)站下載 lucene 的開(kāi)發(fā)包,并配置好環(huán)境變量
http://jakarta.apache.org/lucene/docs/index.html

建立索引程序:
/*
 * Created on 2004-4-26
 */

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

/**
 * @author bell.wang
 */
public class IndexFiles {

 public static void main(String[] args) {
  try{
   IndexWriter writer = new IndexWriter("myindex", new StandardAnalyzer(), true);
      
   
   File files = new File("mydoc");
   String[] Fnamelist = files.list();
   for (int i = 0; i < Fnamelist.length; i++){
    File file = new File(files,Fnamelist[i]);
      
    Document doc = new Document();
    Field fld = Field.Text("path", file.getPath());
    doc.add(fld);
   
    fld = Field.Keyword("modified", DateField.timeToString(file.lastModified()));
    doc.add(fld);
       
    FileInputStream in = new FileInputStream(file);
    Reader reader = new BufferedReader(new InputStreamReader(in));
    fld = Field.Text("contents", reader);
    doc.add(fld);
    
    writer.addDocument(doc);
    System.out.println("Added : " + doc.get("path"));  
     
   }    
   writer.optimize();
   writer.close();
   System.out.println("Has Added Total: " + Fnamelist.length);
  }catch(Exception e){
   System.out.println(e);
  }
 
 }

}

程序對當前路徑下mydoc目錄下所有文件建立索引,其中索引有三個(gè)字段: 文件路徑,
最后修改時(shí)間,文件內容.  建立的索引文件在當前路徑下的myindex目錄

檢索程序:
/*
 * Created on 2004-4-26
 *
 */
import org.apache.lucene.analysis.*;
import org.apache.lucene.analysis.standard.*;
import org.apache.lucene.search.*;
import org.apache.lucene.queryParser.*;
import org.apache.lucene.document.*;
//import com.augmentum.hrms.*;
import java.util.Date;
/**
 * @author bell.wang
 *
 */
public class SearchFile {

 public static void main(String[] args) {
 
  //XMap a = new XMap("");
  Analyzer anlzr = new StandardAnalyzer();
  try{
   Query q = QueryParser.parse("數據庫", "contents", anlzr);
   System.out.println("Searching for : " + q.toString("contents"));
   
   Searcher serch = new IndexSearcher("myindex");
   Hits hts = serch.search(q);
   for(int i=0; i<hts.length(); i++){
    Document doc = hts.doc(i);
    String path = doc.get("path");
    System.out.println("Find: " +i+": "+ path);
    System.out.println("Find: " + doc.get("modified"));
    System.out.println("Find: " + doc.get("path"));
   }
   System.out.println("Find Total: " + hts.length());
  }catch(Exception e){
   System.out.println(e);
  }
 }
}

程序對索引的contents字段用“數據庫“關(guān)鍵字進(jìn)行查詢(xún),返回
的是所有包含有關(guān)鍵字的文檔集合,分別打印出各個(gè)字段.

上面的程序我用純文本文件測試通過(guò),.txt,.jsp,.html 都可以,
word,pdf 等文件需要經(jīng)過(guò)轉化才能對其進(jìn)行索引。
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
用Lucene檢索數據庫
[原創(chuàng )]全文搜索引擎Lucene學(xué)習筆記(頁(yè) 1) - 『 編程設計 』 - 青韶論壇 湘...
Lucene
Lucene簡(jiǎn)單實(shí)現文件索引及查詢(xún)
lucene多種搜索方式詳解例子
Lucene版Hello world(世界,你好)
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久