1. 在eclipse中安装配置lucene
a) 下载lucene-core-2.3.2.jar
b) File->new java project->properties->javabuild path->add external jars: lucene-core-2.3.2.jar
c) 为支持中文搜索,和导入lucene-core-2.3.2.jar相同的方式导入je-analysis-1.5.3.jar
在电脑中D盘建立lucene/docs的文件夹,其中包含要被检索的文档集合
在电脑中D盘建立index文件夹,用于存储索引
2. 索引相关的程序
a) 建立索引
package index;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import jeasy.analysis.MMAnalyzer;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.store.LockObtainFailedException;
public class Create {
static String docDirPath = "D://lucene/docs";
static String indexDirPath = "D://lucene/index";
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
File docDir = new File(docDirPath);
File indexDir = new File(indexDirPath);
File[] docFiles = docDir.listFiles();
//StandardAnalyzer analyzer = new StandardAnalyzer();
Analyzer analyzer = new MMAnalyzer();