`
- 浏览:
372247 次
- 性别:
- 来自:
北京
-
今天更新网站的搜索引擎到Lucene 2.4.0 ,这个是 2008年10月8日发布的版本,结果发现许多方法和类被声明为过期(@deprecated),且某些方法和类被声明在3.0引擎中将被删除。我这里只写出自己用到的几个方法和类,并替换为新版本的。
1 IndexWriter 的构造器
IndexWriter writer = new IndexWriter(indexPath, getAnalyzer(), true);
其中
indexPath 为目录,是一个字符串,
getAnalyzer()是分析器
true 代表重建索引
这个方法需要替换为
IndexWriter writer = new IndexWriter(indexPath, getAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);
其中前面三个完全相同,
第四个参数代表允许的最大字段长度,UNLIMITED代表不限制长度
2 Field.Index.UN_TOKENIZED
这个被替换为
Field.Index.NOT_ANALYZED
没啥特殊的,改了一个名字而已
Field.Index.TOKENIZED 替换为 Field.Index.ANALYZED
3 IndexWriter.flush();
替换为
IndexWriter.commit();
4 org.apache.lucene.search.Hits;
这个类将在3.0中被删除
新的搜索代码如下
IndexSearcher isearcher = new IndexSearcher(indexPath);
BooleanClause.Occur[] clauses = { BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD };
TopDocCollector collector = new TopDocCollector(10); // 启用这个
Query query = MultiFieldQueryParser.parse(queryString, new String[] { "subject", "content" }, clauses, getAnalyzer());
isearcher.search(query, collector); // 作为参数
ScoreDoc[] hits = collector.topDocs().scoreDocs; // 拿到结果
List<Long> rtn = new ArrayList<Long>();
Long id;
Long idParent;
int docId;
for (int i = 0; i < hits.length; i++) { // 循环
docId = hits[i].doc; // 一个内部编号
Document doc = isearcher.doc(docId); // 通过编号,拿到文档
}
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
Lucene2.4入门总结lucene2.4 人门 field 多条件搜索
lucene 2.4 jar lucene2.4版本的JAR包
java拼车网雏形(Ext2.0+SSH+oracle10g+lucene2.4)
ictclas4j for lucene 2.4 任何人不得将此用于商业用途,仅限个人学习研究之用.该开源项目遵循Apache License 2.0
能够直接运行的Lucene2.4样例以及全面注释; + Lucene中文文档,能够帮助你最快掌握Lucene2.4
庖丁解牛 源码 for Lucene 2.4
Luene2.4版本在以前的基础上进行了不少的改动,性能上也提升了不少,这里边学习边写了一个简单的例子,给初学者行个方便!
struts2 + spring2.5 + hibernate 3.2 + lucene 2.4 + compass 2.0 包含所有jar包,按readme.txt导入并运行即可 开始不用分了................
lucene2.4手册,是开发搜索引擎的好帮手.
NULL 博文链接:https://chenhua-1984.iteye.com/blog/380779
支持net4.0环境下运行,Lucene.net版本为3.0,PanGu版本为2.4
Lucene2.4.1的源代码,包括core包和demos包的内容。
lucene-core-2.4.0.jar,lucene-analyzer-2.4.0.jar,lucene-highlighter-2.4.0.jar,je-analysis-1.5.3.jar
信息检索,全文本内容检索,lucene heritrix
几种常见的基于Lucene的开源搜索解决方案对比,大家参考一下。
基于lucene 2.4简单的一个索引和搜索实例
lucene.net用于在.net平台中开发搜索引擎。使得.net开发全文搜索变得很方便。
might not be compatible with the Snowball module in Lucene 2.4 or greater. For more information about this issue see: https://issues.apache.org/jira/browse/LUCENE-1142 For more information on ...
lucene-2.3.1.jar.7z