搜索引擎学习总结(实战和使用场合)
备注以下代码使用的环境为JDK1.5 ,luence 1.4
1. 代码的解析()
使用场合:创建索引的信息,以便于搜索引擎在适当的时候使用。
/**
* 使用递归索引特定的java文件的信息
* @param writer
* @param dir
* @throws Exception
*/
public static void indexDirectory(IndexWriter writer, File dir)
throws Exception {
File[] files = dir.listFiles();
for (File file : files) {
if (file.isDirectory()) {
indexDirectory(writer, file);
} else if (file.getName().endsWith(".java")) {
indexFile(writer, file);
}
}
}
/**
* 设置索引文档的方法
* @param writer
* @param f
* @throws Exception
*/
public static void indexFile(IndexWriter writer, File f) throws Exception {
if (f.isHidden() || !f.exists() || !f.canRead()) {
return;
}
System.out.println("indexing ....." + f.getAbsolutePath());
//虚拟的文档的对象的
Document doc = new Document();
//向文档中添加域对象
doc.add(Field.Text("contents", new FileReader(f)));//索引文件的内容
//创建域对象的
//域中添加域对象的
doc.add(Field.Keyword("filename", f.getCanonicalPath()));
//添加索引的文檔的對象
writer.addDocument(doc);
}
/**
* 创建索引文件的
* @param indexDir 存储索引的目录
* @param dataDir 检索的目录文件家
* @return
* @throws Exception
*/
@SuppressWarnings("deprecation")
public static int index(File indexDir, File dataDir) throws Exception {
if (!dataDir.exists() || !dataDir.isDirectory()) {
throw new IOException(dataDir
+ "does not exists or is not a direcotry");
}
//创建搜索索引的对象IndexWriter
IndexWriter writer =new IndexWriter(indexDir, new StandardAnalyzer(),
true);
//是否使用一个符合文件
writer.setUseCompoundFile(false);
indexDirectory(writer, dataDir);
int numIndexed = writer.docCount();
//优化索引对象
writer.optimize();
//关闭索引对象
writer.close();
return numIndexed;
}
2.代码使用场合:在搜索引擎检索索引目录的中的信息
分享到:
相关推荐
lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习...
lucene 2.9 API , lucene API,lucene 学习资料,lucene2.9 CHM
用来测试luence运行的结果是否正确。运行直接使用即可。
完整的IKanalyzer2012和luence4.3.0、luence3.6.1的压缩包,内含有IKAnalyzer2012的说明文档
Luence和ElasticSearch面试准备.docx
获取全部Luence数据
lucene 原理与分析,底层源码解析,应用场景及实践,相关配置
Luence.Net搜索Demo
Luence in Action 中英文 pdf
luence4.6 源代码
利用Luence.net做的搜索,实现搜索高亮,盘古分词,只能匹配,是做搜索的好例子。
下载可运行。 使用前后端分离架构, 使用springMvc 、 spring、 mybatis、 luence等技术开发的开源知识库所有后台代码
包含翻译后的API文档:lucene-core-7.3.1-javadoc-API文档-中文(简体)版.zip; Maven坐标:org.apache.lucene:lucene-core:7.3.1; 标签:apache、lucene、core、中文文档、jar包、java; 使用方法:解压翻译后的API...
使用luence索引数据库中的记录,完整的例子
lucene基础学习笔记&源码
首先读取文件,添加数据库记录,然后lucene读取数据库生成索引文件,再通过lucene检索
基于ajax与luence构建搜索引擎的设计和实现论文.doc
VerticalSearcher基本的垂直搜索引擎,实现了基本的网络爬虫功能以及用Luence实现检索
基于ajax与luence构建搜索引擎的设计和实现_论文.doc
stopword+dic 分词器分析