使用Lucene 2.31 索引 Oracle 10g的資料庫

來源:互聯網
上載者:User

1,使用主要技術:
Lucene 2.3.1
IK_CAnalyzer 1.4 中文分詞
HtmlParser 1.6 HTML檔案/文本解析器 缺點:不能忽略<!----->的內容


2,其他實現方法:

每天做對每類做增量索引 索引內容:類型,URL,TEXT內容,標題,作者,時間。

3,在Oracle 10g上建表:

-- Create table
create table IZ_SEARCH_ENGINE
(
  ID             NUMBER not null,
  INDEX_DIR      VARCHAR2(50),
  TYPE           VARCHAR2(500),   類型
  TYPE_DESC      VARCHAR2(50),  類型注釋
  TABLE_MAXVALUE VARCHAR2(50), 某表最大值
  TABLE_SQLS     CLOB,  (最某表沒有被索引的SQL語句,如select .... from XXX where id>#ID# ,  #ID# 取自TABLE_MAXVALUE )
  STATUS         VARCHAR2(20) default 'offline', 暫時無用
  TYPE_TRUETYPE  VARCHAR2(50) 暫時無用
)

4,建立索引的JAVA關鍵代碼:

String INDEX_DIR = “/home/xue24_index_book”; //指定索引目錄
IndexWriter writer = new IndexWriter(INDEX_DIR, new IK_CAnalyzer(), true); //準備索引區,並指定分詞分析器
Document doc = new Document(); //執行個體化新document
doc.add(new Field(“type”, “社區”, Field.Store.YES, Field.Index.TOKENIZED)); //為document設定欄位:type
doc.add(new Field(“title”, “標題標題” Field.Store.YES, Field.Index.TOKENIZED)); //為document設定欄位:title
writer.addDocument(doc); //將該document加入索引目錄
writer.optimize();  //最佳化
writer.close();  //關閉索引

5,搜尋的JSP關鍵代碼:

String INDEX_DIR_BOOK = "/home/xue24_index/book";
String INDEX_DIR_BBS = "/home/xue24_index/bbs";

Searcher[] searchers=new Searcher[2];
searchers[0] = new IndexSearcher(INDEX_DIR_BOOK);
searchers[1] = new IndexSearcher(INDEX_DIR_BBS);

Searcher searcher = new MultiSearcher(searchers);
MultiFieldQueryParser queryParser = new MultiFieldQueryParser(new String[] {"title","content","author" }, new IK_CAnalyzer());
Query query = queryParser.parse(keyword); //分析查詢

Hits hits = searcher.search(query);//  搜尋索引
out.println(“共找到結果:”+hits.length());
for(int i=0;i<hits.length(); i++){
   Document doc = hits.doc(i);
   out.println(“標題:” +doc.get("title") );
}


6,再寫一個linux cron 定期執行,或用quartz外掛程式來完成增量索引。

Lucene 的詳細介紹:請點這裡
Lucene 的:請點這裡

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.