这是其中的创建索引的代码:大家帮忙看下吧
package com.foresee.paodinganalyzer;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Date;
import net.paoding.analysis.analyzer.PaodingAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.store.FSDirectory;
public class CreateIndexer {
/**
* @param args
*/
private static String INDEX_DIR = "e:\\mypaoding\\index\\";// 索引存放目录
private static String DATA_DIR = "e:\\mypaoding\\small\\";// 原文件存放路径
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
long start = new Date().getTime();
int numIndexed = index(new File(INDEX_DIR), new File(DATA_DIR));// 调用index方法
long end = new Date().getTime();
System.out.println("Indexing " + numIndexed + " files took "
+ (end - start) + " millseconds");
}
private static int index(File indexDir, File dataDir) throws IOException {
// TODO Auto-generated method stub
if (!dataDir.exists() || !dataDir.isDirectory()) {
throw new IOException(dataDir
+ " does not exist or is not a directory");
}
IndexWriter iw = new IndexWriter(FSDirectory.open(indexDir),
new PaodingAnalyzer()/*new StandardAnalyzer(Version.LUCENE_30)*/, true, IndexWriter.MaxFieldLength.LIMITED);
indexDirectory(iw, dataDir);
int numIndexed = iw.numDocs();
iw.optimize();
iw.close();
return numIndexed;
}
/**
* 循环遍历目录下的所有.txt文件并进行索引
*
* @param iw
* @param dataDir
* @throws IOException
*/
private static void indexDirectory(IndexWriter iw, File dataDir)
throws IOException {
// TODO Auto-generated method stub
File[] files = dataDir.listFiles();
for (int i = 0; i < files.length; i++) {
File f = files[i];
if (f.isDirectory()) {
indexDirectory(iw, f);// 递归遍历
} else if (f.getName().endsWith(".txt")) {
indexFile(iw, f);
}
}
}
private static void indexFile(IndexWriter iw, File f) throws IOException {
// TODO Auto-generated method stub
if (f.isHidden() || !f.exists() || !f.canRead()) {
return;
}
System.out.println("Indexing " + f.getCanonicalPath());
Document doc = new Document();
doc.add(new Field("contents", new FileReader(f)));// 有变化的地方
doc.add(new Field("filename", f.getCanonicalPath(), Field.Store.YES,
Field.Index.ANALYZED));// 有变化的地方
iw.addDocument(doc);
}
}
下面是报错的信息:
2010-3-10 9:16:00 net.paoding.analysis.knife.PaodingMaker getProperties
信息: config paoding analysis from: D:\workspace\PaodingAnalyzer\file:\E:\jar\pading\paoding-analysis.jar!\paoding-analysis.properties;D:\workspace\PaodingAnalyzer\file:\E:\jar\pading\paoding-analysis.jar!\paoding-analysis-default.properties;D:\workspace\PaodingAnalyzer\file:\E:\jar\pading\paoding-analysis.jar!\paoding-analyzer.properties;D:\workspace\PaodingAnalyzer\bin\paoding-dic-home.properties;E:\data\paoding\dic\paoding-dic-names.properties;D:\workspace\PaodingAnalyzer\file:\E:\jar\pading\paoding-analysis.jar!\paoding-knives.properties;D:\workspace\PaodingAnalyzer\file:\E:\jar\pading\paoding-analysis.jar!\paoding-knives-user.properties
2010-3-10 9:16:00 net.paoding.analysis.knife.PaodingMaker createPaodingWithKnives
信息: add knike: net.paoding.analysis.knife.CJKKnife
2010-3-10 9:16:00 net.paoding.analysis.knife.PaodingMaker createPaodingWithKnives
信息: add knike: net.paoding.analysis.knife.LetterKnife
2010-3-10 9:16:00 net.paoding.analysis.knife.PaodingMaker createPaodingWithKnives
信息: add knike: net.paoding.analysis.knife.NumberKnife
Indexing E:\mypaoding\small\girl0.txt
Exception in thread "main" java.lang.AbstractMethodError: org.apache.lucene.analysis.TokenStream.incrementToken()Z
at org.apache.lucene.index.DocInverterPerField.processFields(DocInverterPerField.java:137)
at org.apache.lucene.index.DocFieldProcessorPerThread.processDocument(DocFieldProcessorPerThread.java:246)
at org.apache.lucene.index.DocumentsWriter.updateDocument(DocumentsWriter.java:773)
at org.apache.lucene.index.DocumentsWriter.addDocument(DocumentsWriter.java:751)
at org.apache.lucene.index.IndexWriter.addDocument(IndexWriter.java:1928)
at org.apache.lucene.index.IndexWriter.addDocument(IndexWriter.java:1902)
at com.foresee.paodinganalyzer.CreateIndexer.indexFile(CreateIndexer.java:81)
at com.foresee.paodinganalyzer.CreateIndexer.indexDirectory(CreateIndexer.java:66)
at com.foresee.paodinganalyzer.CreateIndexer.index(CreateIndexer.java:43)
at com.foresee.paodinganalyzer.CreateIndexer.main(CreateIndexer.java:29)