- 浏览: 303992 次
- 性别:
- 来自: 重庆
文章分类
- 全部博客 (286)
- 设计模式 (14)
- spring (5)
- 开发工具 (12)
- java (19)
- apache.commons工具 (7)
- ibaits (5)
- extjs4.0 (4)
- 数据库 (2)
- spring工具类 (2)
- jquery1.8 (32)
- 杂记 (1)
- linux (2)
- Quart (1)
- springMVC (2)
- webservice (1)
- oracle (5)
- dwr (6)
- jbmp3 (27)
- lucene3.5 (27)
- javascript (18)
- hibernate3.3.2 (27)
- spring事务管理 (10)
- nio (2)
- strust2 (3)
- jvm (7)
- jquery-easyui-1.2.6 (22)
- 多线程 (14)
- maven (3)
- 常用正则表达式 (4)
最新评论
-
HF_SKY000:
请问:
一、能否提供一下密钥库文件的生成方法?
二、密钥库的密 ...
Java sslSocket 聊天实例
环境搭建:
1、lucene-core-3.5.0.jar
2、mmseg4j-all-1.8.5-with-dic.jar(中文分词器)
3、lucene-highlighter-3.5.0.jar、lucene-memory-3.5.0.jar(高亮显示)
在全文索引工具中,都是由这样的三部分组成
1、索引部分(I am a boy)
2、分词部分
3、搜索部分
/** * 建立索引 */ public void index() { //1、创建Directory //Directory directory = new RAMDirectory();//建立在内存中 Directory directory = null; try { directory = FSDirectory.open(new File("D:/test/index01")); } catch (IOException e1) { e1.printStackTrace(); } //2、创建IndexWriter IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_36, new StandardAnalyzer( Version.LUCENE_36)); IndexWriter writer = null; try { writer = new IndexWriter(directory, config); //3、创建Document对象 Document document = null; //4、为Document添加Field Collection<File> files = FileUtils.listFiles(new File("D:/test/lucene"), FileFileFilter.FILE, null); for (File file : files) { document = new Document(); document.add(new Field("content", new FileReader(file))); document.add(new Field("filename", file.getName(), Field.Store.YES, Field.Index.NOT_ANALYZED)); document.add(new Field("path", file.getAbsolutePath(), Field.Store.YES, Field.Index.NOT_ANALYZED));//是否存储路径,是否进行分词 writer.addDocument(document); } //5、通过IndexWriter添加对象到索引中 } catch (CorruptIndexException e) { e.printStackTrace(); } catch (LockObtainFailedException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (writer != null) { try { writer.close(); } catch (CorruptIndexException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } } /** * 搜索 */ public void searcher() { try { //1、创建Directory Directory directory = FSDirectory.open(new File("D:/test/index01")); //2、创建IndexReader IndexReader reader = IndexReader.open(directory); //3、根据IndexReader创建IndexSearcher IndexSearcher searcher = new IndexSearcher(reader); //4、创建搜索的Query QueryParser parser = new QueryParser(Version.LUCENE_36, "content", new StandardAnalyzer(Version.LUCENE_36));//content表示搜索的Field Query query = parser.parse("File");//表示内容中含有“File”的 //5、根据searcher搜索并返回TopDocs TopDocs topDocs = searcher.search(query, 10);//只搜索10条 //6、根据TopDocs对象获取ScoreDoc对象 ScoreDoc[] sds = topDocs.scoreDocs; for (ScoreDoc scoreDoc : sds) { //7、根据searcher和ScoreDoc对象获取具体的Document对象 Document document = searcher.doc(scoreDoc.doc); //8、根据Document对象获取需要的值 System.out.println(document.get("filename")); System.out.println(document.get("path")); } //9、关闭reader reader.clone(); } catch (Exception e) { e.printStackTrace(); } }
发表评论
-
二十七、Luence在项目中运用
2012-12-26 15:03 1048public class LuceneContext { ... -
二十六、solr的基本使用
2012-12-26 10:26 935public class Message { p ... -
二十五、solr与tomcat的整合
2012-12-25 13:52 10211、solr是全文搜索服务器,专门用户管理索引的。 2 ... -
二十四、通过NRTManager和SearchManager实现近实时搜索
2012-12-21 11:35 1318是否进行实时搜索 实时搜索(近实时搜索) ... -
二十三、高亮显示
2012-12-20 09:24 979public void lighter01() { ... -
二十二、Tika
2012-12-20 09:24 927Tika是2008年才产生的一个apache的项目,主要用于打 ... -
二十一、Luke
2012-12-20 09:24 773luke是一个查询索引的工具,使用时必须注意:版本要与luce ... -
二十、自定义过滤器
2012-12-20 09:23 843有的应用有些要求,对于某类型的内容即使满足条件了,但是也不 ... -
十七、搜索过滤
2012-12-20 09:23 602public void searcherByFilter(St ... -
十九、自定义QueryParser
2012-12-19 16:28 1197原因: 1、对于某些Quer ... -
十八、自定义评分
2012-12-19 16:18 763public class MyCustomScoreProvi ... -
十六、搜索排序
2012-12-19 12:14 1000public void searcherBySort(Stri ... -
十五、实现简单同义词分词器
2012-12-19 11:41 1226public interface SamewordContex ... -
十四、中文分词器
2012-11-28 13:49 829中文分词器 : Paoding:庖丁解牛分词器。 ... -
十三、自定义Stop分词器
2012-11-28 13:42 736import java.io.Reader; impor ... -
十二、Attribute
2012-11-28 13:20 788Attribute : ... -
十一、分词器的核心类
2012-11-28 13:12 873Analyzer : SimpleAnalyz ... -
十、分页搜索
2012-11-27 17:30 843分页查询有两种实现方式: 1、再查询 ... -
九、Queryparser
2012-11-27 17:24 958Mike 默认域包含mike Mi ... -
八、其他搜索Query
2012-11-27 10:30 621TermRangeQuery : 字母范围搜索 ...
相关推荐
Directory类代表一个Lucene索引的位置。它是一个抽象类. 其中的两个实现: 第一个是 FSDirectory,它表示一个存储在文件系统中的索引的位置。 第二个是 RAMDirectory,它表示一个存储在内存当中的索引的位置。 ...
lucene实例lucene实例lucene实例lucene实例lucene实例lucene实例lucene实例lucene实例lucene实例
使用其他编程语言访问Lucene Lucene管理和性能调优等内容 最后还提供了三大经典成功案例 为读者展示了一个奇妙的搜索世界 《Lucene实战 第2版 》适合于已具有一定Java编程基本的读者 以及希望能够把强大的搜索...
包括认识Lucene、建立索引、为应用程序添加搜索功能、高级搜索技术、扩展搜索、使用Tika提取文本、Lucene的高级扩展、使用其他编程语言访问Lucene、Lucene管理和性能调优等内容,最后还提供了三大经典成功案例,为...
lucene3.0 lucene3.0 lucene3.0 lucene3.0 lucene3.0
比较全面的一个入门 比较全面的一个入门 比较全面的一个入门 比较全面的一lucene个入门 比较全面的一个入门
lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习lucene学习...
一个基于LUCENE搜索引擎项目例子一个基于LUCENE搜索引擎项目例子一个基于LUCENE搜索引擎项目例子
一种基于Lucene检索引擎的全文数据库的研究与实现一种基于Lucene检索引擎的全文数据库的研究与实现一种基于Lucene检索引擎的全文数据库的研究与实现
包括认识Lucene、建立索引、为应用程序添加搜索功能、高级搜索技术、扩展搜索、使用Tika提取文本、Lucene的高级扩展、使用其他编程语言访问Lucene、Lucene管理和性能调优等内容,最后还提供了三大经典成功案例,为...
Lucene3.0特性Lucene3.0特性
lucenetest.rar,lucene,全文检索,lucene例子 lucenetest.rar,lucene,全文检索,lucene例子lucenetest.rar,lucene,全文检索,lucene例子
Lucene是一个高性能、可伸缩的信息搜索(IR)库。目前最新版本是4.3.1. 它可以为你的应用程序添加索引和搜索能力。Lucene是用java实现的、成熟的开源项目,是著名的Apache Jakarta大家庭的一员,并且基于Apache软件...
相似度评分算法是Lucene引擎中的核心部分之一。对Lucene内部的相似度评分算法进行研究分析后,针对Lucene只关心查询词出现的频率,而不关心它们所在的位置这一缺陷提出了一种改进的算法。改进的算法将词语位置关系...
lucene学习教程lucene讲义 叫你用lucene算法
Lucene是一个全文搜索框架,而不是应用产品。因此它并不像www.baidu.com 或者google Desktop那么拿来就能用,它只是提供了一种工具让你能实现这些产品。 2 lucene的工作方式 lucene提供的服务实际包含两部分:一...
lucene
lucene3源码分析
lucene
Lucene是apache软件基金会4 jakarta项目组的一个子项目,是一个开放源代码的全文检索引擎工具包,即它不是一个完整的全文检索引擎,而是一个全文检索引擎的架构,提供了完整的查询引擎和索引引擎,部分文本分析引擎...