lucene 2.1 中如何切分索引

Ronaldo2010 2007-04-07 09:59:49
我用lucene做了个检索,可是他不能将我的字符串数组
切分开,请那位高手教一下
public class InsertIndexRecord {
public InsertIndexRecord(){

}

public int insertIndexRecord(String dbPath,File file){
int returnValue = 0;

try {
IndexWriter indexWriter = new IndexWriter(dbPath,new StandardAnalyzer(),false);

addFiles(indexWriter,file);

returnValue = 1;
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}

return returnValue;
}

public int insertIndexRecord(String dbPath,String file){
return insertIndexRecord(dbPath,new File(file));
}

public void addFiles(IndexWriter indexWriter,File file){
Document document = new Document();

//document.add(new Field("fileName",file.getName(),Field.Store.YES,Field.Index.UN_TOKENIZED));

document.add(new Field("content",chgFiletoString(file),Field.Store.YES,Field.Index.TOKENIZED));

try {
indexWriter.addDocument(document);

indexWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}

public String chgFiletoString(File file){
String return_value = null;

StringBuffer sb = new StringBuffer();

char[] c = new char[4096];

try {
Reader reader = new FileReader(file);

int n = 0;

int i = 0;

while(true) {
System.out.println(i);

n = reader.read(c);

if(n > 0) {
sb.append(c,0,n);
}else{
break;
}

i++;
}

reader.close();
}catch(Exception e) {
e.printStackTrace();
}

return_value = sb.toString();

return return_value;
}

public static void main(String[] args) {
InsertIndexRecord iir = new InsertIndexRecord();

String dbPath = "d:/lucene";

if(iir.insertIndexRecord(dbPath,"D:/a.txt") == 1){
System.out.println("a.txt添加成功..");
}
}
}

这就是我创建索引的方法,请高手指教!
...全文
152 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
i2u112233 2007-04-09
  • 打赏
  • 举报
回复
bang ding!
Ronaldo2010 2007-04-07
  • 打赏
  • 举报
回复
急啊,请高手帮忙啊
lotuswlz 2007-04-07
  • 打赏
  • 举报
回复
有会答案的给说一下啊
关注
lotuswlz 2007-04-07
  • 打赏
  • 举报
回复
留个记号,等着看答案
顺便帮楼主顶一下
Ronaldo2010 2007-04-07
  • 打赏
  • 举报
回复
a.txt文件内容如下
第一采油厂,
第二采油厂,
第三采油厂,
第四采油厂,
第五采油厂,
第一输油处,
第二输油处,
第三输油处,
王窑站

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧