package bindex;
import java.io.File;
import tool.FileText;
import java.io.IOException;
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;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
public class FileIndexer {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String indexPath ="indexes";
try {
IndexWriter indexWriter = new IndexWriter(indexPath,new StandardAnalyzer());
Document doc=new Document();
//第一个文档
File f=new File("htmls/hao123.htm");
String name=f.getName();
Field field=new Field("name",name,Field.Store.YES,Field.Index.TOKENIZED);
doc.add(field);
String content=FileText.getText(f);
field=new Field("conent",content,Field.Store.YES,Field.Index.TOKENIZED);
doc.add(field);
String path=f.getPath();
field=new Field("path",path,Field.Store.YES,Field.Index.NO);
doc.add(field);
indexWriter.addDocument(doc);
//第二个文档
f=new File("htmls/home.htm");
name=f.getName();
field=new Field("name",name,Field.Store.YES,Field.Index.TOKENIZED);
doc.add(field);
content=FileText.getText(f);
field=new Field("conent",content,Field.Store.YES,Field.Index.TOKENIZED);
doc.add(field);
path=f.getPath();
field=new Field("path",path,Field.Store.YES,Field.Index.NO);
doc.add(field);
indexWriter.addDocument(doc);
indexWriter.close();
System.out.println("OK!");
} catch (CorruptIndexException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (LockObtainFailedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package tool;
import java.io.*;
public class FileText {
/**
* @param args
*/
public static String getText(File f){
StringBuffer sb=new StringBuffer("");
try{
FileReader fr=new FileReader(f);
BufferedReader br=new BufferedReader(fr);
String s=br.readLine();
while(s!=null){
sb.append(s);
s=br.readLine();
}
br.close();
}
catch (Exception e){
sb.append("");
}
return sb.toString();
}
public static String getText(String s){
String t="";
try{
File f=new File(s);
t=getText(f);
}
catch (Exception e){
t="";
}
return t;
}
}
分享到:
相关推荐
lucene入门实战.txt Lucene 的学习 .txt Lucene-2.0学习文档 .txt Lucene入门与使用 .txt lucene性能.txt 大富翁全文索引和查询的例子程序.txt 关于lucene2.0的创建、检索和删除功能的完整实现.doc web...
Hadoop的源起——Lucene ,Doug Cutting开创的开源软件,用java书写代码,实现与Google类似的全文搜索功能,提供了全文检索引擎的架构,包括完整的查询引擎和索引引擎 。
lucene索引入门[归类].pdf
01.Lucene4入门精通实战课程-概述 共23页 02.Lucene系统架构 共16页 03.Lucene索引里有什么 共17页 04.Lucene索引深入 共24页 05.Lucene索引深入优化 共10页 06.Lucene索引搜索 共13页 07.Lucene搜索实战1 共4页 08....
01.Lucene4入门精通实战课程-概述 共23页 02.Lucene系统架构 共16页 03.Lucene索引里有什么 共17页 04.Lucene索引深入 共24页 05.Lucene索引深入优化 共10页 06.Lucene索引搜索 共13页 07.Lucene搜索实战1 共4页 08....
01.Lucene4入门精通实战课程-概述 共23页 02.Lucene系统架构 共16页 03.Lucene索引里有什么 共17页 04.Lucene索引深入 共24页 05.Lucene索引深入优化 共10页 06.Lucene索引搜索 共13页 07.Lucene搜索实战1 共4页 08....
使用lucene,建索引。倒排索引现在在搜索引擎涌出很大,本工程为入门提供参考
lucene.net 完全入门教程,包括 lucene.net 介绍, lucene.net工作模式, lucene.net分词方法和中文分词方法, lucene.net索引的建立详解, lucene.net搜索详解, lucene.net的下载方法, lucene.net搜索结果实现...
Lucene是一个全文检索引擎的架构,提供了完整的查询引擎和索引引擎。Lucene以其方便使用、快速实施以及灵活性受到广泛的关注。它可以方便地嵌入到各种应用中实现针对应用的全文索引、检索功能,本总结使用lucene--...
NULL 博文链接:https://iamyida.iteye.com/blog/2192938
Lucene入门精讲视频教程QQ截图20191025020202.png?x-oss-process=style/pnp8(39.97KB,下载次数:225)下载附件2019-10-2502:02上传〖课程介绍〗:Lucene是apache下的一个开放源代码的全文检索引擎工具包。提供了完整的...
里面编写了法创建,搜索的基本方法 LuceneDemo 单个文件索引,创建查找 CopyFile 为多文件复制多些文件做准备 CreateIndexe 多文件创建索引;Searcher多文件搜索对应CreateIndexe
提供了完整的查询引擎和索引引擎, 部分文本分词引擎。 Lucene的目的是为软件开发人员提供一个简单易用的工具包, 以方便在目标系统中实现全文检索功能, 或者是以此为基础建立起完整的全文检索引擎。
01.Lucene4入门精通实战课程-概述 共23页 02.Lucene系统架构 共16页 03.Lucene索引里有什么 共17页 04.Lucene索引深入 共24页 05.Lucene索引深入优化 共10页 06.Lucene索引搜索 共13页 07.Lucene搜索实战1 共4页 08....
01.Lucene4入门精通实战课程-概述 共23页 02.Lucene系统架构 共16页 03.Lucene索引里有什么 共17页 04.Lucene索引深入 共24页 05.Lucene索引深入优化 共10页 06.Lucene索引搜索 共13页 07.Lucene搜索实战1 共4页 08....
01.Lucene4入门精通实战课程-概述 共23页 02.Lucene系统架构 共16页 03.Lucene索引里有什么 共17页 04.Lucene索引深入 共24页 05.Lucene索引深入优化 共10页 06.Lucene索引搜索 共13页 07.Lucene搜索实战1 共4页 08....
01.Lucene4入门精通实战课程-概述 共23页 02.Lucene系统架构 共16页 03.Lucene索引里有什么 共17页 04.Lucene索引深入 共24页 05.Lucene索引深入优化 共10页 06.Lucene索引搜索 共13页 07.Lucene搜索实战1 共4页 08....
01.Lucene4入门精通实战课程-概述 共23页 02.Lucene系统架构 共16页 03.Lucene索引里有什么 共17页 04.Lucene索引深入 共24页 05.Lucene索引深入优化 共10页 06.Lucene索引搜索 共13页 07.Lucene搜索实战1 共4页 08....
01.Lucene4入门精通实战课程-概述 共23页 02.Lucene系统架构 共16页 03.Lucene索引里有什么 共17页 04.Lucene索引深入 共24页 05.Lucene索引深入优化 共10页 06.Lucene索引搜索 共13页 07.Lucene搜索实战1 共4页 08....