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 的:請點這裡