資源簡介
創建索引
一、創建詞法分析器
二、創建索引存儲目錄
三、創建索引寫入器
四、將內容存儲到索引
關鍵字查詢
一、創建索引存儲目錄讀取器
二、創建索引搜索器
三、解析查詢
四、獲取結果
代碼片段和文件信息
package?lucene;
import?org.apache.lucene.analysis.Analyzer;
import?org.apache.lucene.analysis.standard.StandardAnalyzer;
import?org.apache.lucene.document.Document;
import?org.apache.lucene.index.IndexWriter;
import?org.apache.lucene.queryParser.QueryParser;
import?org.apache.lucene.search.IndexSearcher;
import?org.apache.lucene.search.Query;
import?org.apache.lucene.search.ScoreDoc;
import?org.apache.lucene.store.Directory;
import?org.apache.lucene.store.RAMDirectory;
public?class?LuceneDemo?{
//?============?創建索引?=============
//?一、創建詞法分析器
Analyzer?analyzer?=?new?StandardAnalyzer();
//?二、創建索引存儲目錄
//?Store?the?index?in?memory:
Directory?directory?=?new?RAMDirectory();
//?To?store?an?index?on?disk?use?this?instead:
//Directory?directory?=?FSDirectory.open(“/tmp/testindex“);
//?三、創建索引寫入器
IndexWriterConfig?config?=?new?IndexWriterConfig(analyzer);
IndexWriter?iwriter?=?new?IndexWriter(directory?config);
- 上一篇:java課程設計含源代碼
- 下一篇:Android歌詞播放的實現
評論
共有 條評論