LUCENE第一个小程序(有错)
来源:互联网 发布:自建app软件下载 编辑:程序博客网 时间:2024/05/12 08:24
//照着课本抄的都有错 为什么?、?/???????????
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
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.index.IndexWriterConfig;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.LockObtainFailedException;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.Version;
public class HelloLucene {
/**
* @param args
*/
public static void index()throws IOException
{
// Directory directory=new RAMDirectory() ;
Directory directory=FSDirectory.open(new File("g:/lucene/first1") );
IndexWriterConfig iwc=new IndexWriterConfig(Version.LUCENE_35, new StandardAnalyzer(Version.LUCENE_35));
IndexWriter writer=null;
try
{writer=new IndexWriter(directory,iwc);
Document doc=null;
File f=new File("g:/lucene");
for (File file:f.listFiles())
{
doc=new Document();
doc.add(new Field("contend",new FileReader(file)));
doc.add(new Field("filename",file.getName(),Field.Store.YES,Field.Index.NOT_ANALYZED));
doc.add(new Field("filepath",file.getAbsolutePath(), Field.Store.YES, Field.Index.NOT_ANALYZED));
writer.addDocument(doc);
}
}
catch (CorruptIndexException e)
{
e.printStackTrace();
}
catch (LockObtainFailedException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
if (writer!=null)
writer.close();
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
index();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
- LUCENE第一个小程序(有错)
- lucene第一个小程序
- 第一个lucene程序
- 写了第一个lucene程序(lucene学习笔记)
- lucene001 第一个Lucene程序
- 第一个小程序
- 第一个小程序
- Lucene学习笔记:第一个程序
- 我的第一个 lucene程序
- Lucene入门,第一个HelloWorld程序
- Android第一个小程序(手电筒)
- 第一个php小程序(学习)
- WindowsWorkFlow第一个小程序
- 第一个ajax小程序
- 第一个OpenGLES小程序
- 第一个J2ME小程序
- 第一个python小程序
- 1->第一个小程序
- URI is not hierarchical
- CPCI 视频处理卡
- Silverlight:如何打包Theme
- 三大框架的工作原理(Struts1、Struts2、Spring、Hibernate)
- 一个牛x的mock框架--Powermock
- LUCENE第一个小程序(有错)
- 万用表检测常用元器件的方法
- 解决Android Listview横向滑动
- Silverlight中的DataContext和ItemsSource 数据绑定
- android.view.InflateException: Binary XML file line #异常的解决
- C/C++内存问题检查利器—Purify之系列文章
- 0.4 开发简介
- 迷宫最短路径的C++实现(队列:广度优先)
- Android的Handler