- 浏览: 3506882 次
- 性别:
- 来自: 杭州
文章分类
- 全部博客 (1491)
- Hibernate (28)
- spring (37)
- struts2 (19)
- jsp (12)
- servlet (2)
- mysql (24)
- tomcat (3)
- weblogic (1)
- ajax (36)
- jquery (47)
- html (43)
- JS (32)
- ibatis (0)
- DWR (3)
- EXTJS (43)
- Linux (15)
- Maven (3)
- python (8)
- 其他 (8)
- JAVASE (6)
- java javase string (0)
- JAVA 语法 (3)
- juddiv3 (15)
- Mule (1)
- jquery easyui (2)
- mule esb (1)
- java (644)
- log4j (4)
- weka (12)
- android (257)
- web services (4)
- PHP (1)
- 算法 (18)
- 数据结构 算法 (7)
- 数据挖掘 (4)
- 期刊 (6)
- 面试 (5)
- C++ (1)
- 论文 (10)
- 工作 (1)
- 数据结构 (6)
- JAVA配置 (1)
- JAVA垃圾回收 (2)
- SVM (13)
- web st (1)
- jvm (7)
- weka libsvm (1)
- weka屈伟 (1)
- job (2)
- 排序 算法 面试 (3)
- spss (2)
- 搜索引擎 (6)
- java 爬虫 (6)
- 分布式 (1)
- data ming (1)
- eclipse (6)
- 正则表达式 (1)
- 分词器 (2)
- 张孝祥 (1)
- solr (3)
- nutch (1)
- 爬虫 (4)
- lucene (3)
- 狗日的腾讯 (1)
- 我的收藏网址 (13)
- 网络 (1)
- java 数据结构 (22)
- ACM (7)
- jboss (0)
- 大纸 (10)
- maven2 (0)
- elipse (0)
- SVN使用 (2)
- office (1)
- .net (14)
- extjs4 (2)
- zhaopin (0)
- C (2)
- spring mvc (5)
- JPA (9)
- iphone (3)
- css (3)
- 前端框架 (2)
- jui (1)
- dwz (1)
- joomla (1)
- im (1)
- web (2)
- 1 (0)
- 移动UI (1)
- java (1)
- jsoup (1)
- 管理模板 (2)
- javajava (1)
- kali (7)
- 单片机 (1)
- 嵌入式 (1)
- mybatis (2)
- layui (7)
- asp (12)
- asp.net (1)
- sql (1)
- c# (4)
- andorid (1)
- 地价 (1)
- yihuo (1)
- oracle (1)
最新评论
-
endual:
https://blog.csdn.net/chenxbxh2 ...
IE6 bug -
ice86rain:
你好,ES跑起来了吗?我的在tomcat启动时卡在这里Hibe ...
ES架构技术介绍 -
TopLongMan:
...
java public ,protect,friendly,private的方法权限(转) -
贝塔ZQ:
java实现操作word中的表格内容,用插件实现的话,可以试试 ...
java 读取 doc poi读取word中的表格(转) -
ysj570440569:
Maven多模块spring + springMVC + JP ...
Spring+SpringMVC+JPA
Lucene自带示例精简,只留下了主要代码。以备查看
对文件夹生成索引
- package zhch.illq.lucene;
- import java.io.File;
- import java.io.FileReader;
- import java.io.IOException;
- import net.paoding.analysis.analyzer.PaodingAnalyzer;
- import org.apache.lucene.analysis.standard.StandardAnalyzer;
- import org.apache.lucene.document.DateTools;
- import org.apache.lucene.document.Document;
- import org.apache.lucene.document.Field;
- import org.apache.lucene.index.IndexWriter;
- import org.apache.lucene.store.FSDirectory;
- import org.apache.lucene.util.Version;
- public class LuceneIndex {
- static final File INDEX_DIR = new File( "d:\\temp\\index" );
- // 主要代码 索引docDir文件夹下文档,索引文件在INDEX_DIR文件夹中
- public static void main(String[] args) {
- File docDir = new File( "d:\\temp\\neirong" );
- try {
- IndexWriter standardWriter = new IndexWriter(FSDirectory.open(INDEX_DIR), new StandardAnalyzer(
- Version.LUCENE_CURRENT), true , IndexWriter.MaxFieldLength.LIMITED);
- // 如果是索引中文内容,可以使用Paoding中文分词器
- IndexWriter writer = new IndexWriter(FSDirectory.open(INDEX_DIR), new PaodingAnalyzer(), true ,
- IndexWriter.MaxFieldLength.LIMITED);
- String[] files = docDir.list();
- for (String fileStr : files) {
- File file = new File(docDir, fileStr);
- if (!file.isDirectory()) {
- writer.addDocument(document(file));
- }
- }
- writer.optimize();
- writer.close();
- } catch (IOException e) {
- System.out.println(" caught a " + e.getClass() + "\n with message: " + e.getMessage());
- }
- }
- public static Document document(File f) throws java.io.FileNotFoundException {
- Document doc = new Document();
- // 添加path,索引(可查询)但不切词
- doc.add(new Field( "path" , f.getPath(), Field.Store.YES, Field.Index.NOT_ANALYZED));
- // 添加最后修改日期
- doc.add(new Field( "modified" , DateTools.timeToString(f.lastModified(), DateTools.Resolution.MINUTE),
- Field.Store.YES, Field.Index.NOT_ANALYZED));
- // 添加内容,指定一个Reader,文件内容解析但不存储,这里的Reader使用系统默认的编码读入
- doc.add(new Field( "contents" , new FileReader(f)));
- return doc;
- }
- }
对索引进行查询
- package zhch.illq.lucene;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import net.paoding.analysis.analyzer.PaodingAnalyzer;
- import org.apache.lucene.analysis.Analyzer;
- import org.apache.lucene.analysis.standard.StandardAnalyzer;
- import org.apache.lucene.document.Document;
- import org.apache.lucene.index.IndexReader;
- import org.apache.lucene.queryParser.QueryParser;
- import org.apache.lucene.search.IndexSearcher;
- import org.apache.lucene.search.Query;
- import org.apache.lucene.search.ScoreDoc;
- import org.apache.lucene.search.Searcher;
- import org.apache.lucene.search.TopScoreDocCollector;
- import org.apache.lucene.store.FSDirectory;
- import org.apache.lucene.util.Version;
- public class LuceneSearch {
- /** Simple command-line based search demo. */
- public static void main(String[] args) throws Exception {
- String index = "d:\\temp\\index" ;
- String field = "contents" ;
- String queries = null ;
- boolean raw = false ;
- // 要显示条数
- int hitsPerPage = 10 ;
- // searching, so read-only=true
- IndexReader reader = IndexReader.open(FSDirectory.open(new File(index)), true ); // only
- Searcher searcher = new IndexSearcher(reader);
- Analyzer standardAnalyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);
- // 如果是索引中文内容,可以使用Paoding中文分词器
- Analyzer analyzer = new PaodingAnalyzer();
- BufferedReader in = new BufferedReader( new InputStreamReader(System.in));
- QueryParser parser = new QueryParser(field, analyzer);
- while ( true ) {
- if (queries == null ) // prompt the user
- System.out.println("Enter query: " );
- String line = in.readLine();
- if (line == null || line.length() == - 1 )
- break ;
- line = line.trim();
- if (line.length() == 0 )
- break ;
- Query query = parser.parse(line);
- System.out.println("Searching for: " + query.toString(field));
- doPagingSearch(in, searcher, query, hitsPerPage, raw, queries == null );
- }
- reader.close();
- }
- public static void doPagingSearch(BufferedReader in, Searcher searcher, Query query, int hitsPerPage, boolean raw,
- boolean interactive) throws IOException {
- TopScoreDocCollector collector = TopScoreDocCollector.create(hitsPerPage, false );
- searcher.search(query, collector);
- ScoreDoc[] hits = collector.topDocs().scoreDocs;
- int end, numTotalHits = collector.getTotalHits();
- System.out.println(numTotalHits + " total matching documents" );
- int start = 0 ;
- end = Math.min(hits.length, start + hitsPerPage);
- for ( int i = start; i < end; i++) {
- Document doc = searcher.doc(hits[i].doc);
- String path = doc.get("path" );
- if (path != null ) {
- System.out.println((i + 1 ) + ". " + path);
- System.out.println(" modified: " + doc.get( "modified" ));
- } else {
- System.out.println((i + 1 ) + ". " + "No path for this document" );
- }
- }
- }
-
}
相关推荐
lucene全文检索示例 demo+jar包
lucene3.0.3搜索的使用示例lucene3.0.3搜索的使用示例lucene3.0.3搜索的使用示例
Lucene7.4官方示例,内含若干官方实例,可用于学习Lucene
今天发一个简单的和数据库交互的Lucene示例,只是初步的靠Lucene自带的分词实现中文分词,效果肯定没有网上琳琅的分词器相媲美,只为了示例,用了自带的高亮。页面不好看,将就一下哦。 主要是由 Spring + Struts1 +...
Lucene6.6.2代码示例,处理的原始数据类型是数据库,内含中文分词器IKAnalyzer-6.5.0.jar,支持Lucene6.x以上版本
lucene facet查询示例,区间查询多dim查询,key-field-value模型了解
Lucene简单实例记录 简单Luncene的示例应用
用lucene 4.7.1做的一个Lucene构建索引、进行查询,对比默认的相似度计算与BM25相似度计算输出结果的示例。内容不多,供新手参考
完整的lucene示例,用于搜索指定网站内的所有url资源 能很好的嵌入在你自己的项目中,实现站内搜索 very good ,vert strong
对于初学者很快掌握lucene 该文档详细的介绍了如何使用lucene 以及快速理解掌握lucene
各种分词器都用了,有ikAnalyzer和smartChineseAnalyzer等等分词器。使用jdk7,Lucene-core4.5。非常不错。
自己写的一个Java lucene查询数据库的示例,内部有数据库脚本,SqlServer 2005数据库
最受欢迎的java开源全文搜索引擎开发工具包。 提供了完整的查询引擎和... Lucene的目的是为软件开发人员提供一个简单易用的工具包, 以方便在目标系统中实现全文检索功能, 或者是以此为基础建立起完整的全文检索引擎。
NULL 博文链接:https://blaiu.iteye.com/blog/588054
自己做的一些 lucene4.0的 demo 希望能帮助各位 写的不好 亲们 别喷我
盘古分词 lucene3.0.3 使用 示例 可以方便地整合到项目中使用,.net 4.0的。
易懂的lucene示例代码,可以用来做开发
一步一步跟我学习lucene是对近期做lucene索引的总结,大家有问题的话联系本人的Q-Q: 891922381,同时本人新建Q-Q群:106570134(lucene,solr,netty,hadoop),如蒙加入,不胜感激,大家共同探讨,本人争取每日一博,...
盘古分词 lucene3.0.3 使用 示例 可以方便地整合到项目中使用,.net 4.0的。新加分页功能。
lucene实例lucene实例lucene实例lucene实例lucene实例lucene实例lucene实例lucene实例lucene实例