public class DBIndex{ public static final config _$=new config(); public static class config{ public static final Analyzer analyzer=new StandardAnalyzer(Version.LUCENE_47);//分词器 public String CLASS_PATH= Config.CLASS_PATH; public config(){ } public String getDatePath() { return CLASS_PATH+"query/index"; } public File getDataFile(){ return new File(getDatePath()); } public String getIndexPath() { return CLASS_PATH+"query/index"; } public File getIndexFile(){ return new File(getIndexPath()); } /** * 将字符串中HTML标记清空 * @param msg * @return String */ public String clearHTMLToString(String msg){ if(StringUtils.isEmpty(msg)){ return ""; } return msg.replaceAll("(?is)<(.*?)>","").replaceAll("\\s*|\t|\r|\n",""); } /**将查询出的Map对象,转换为Lucene中的Document对象。 * @param news * @return org.apache.lucene.document.Document * */ public void toDocument(IndexWriter iw,Map<String,Object> news)throws Exception{ Document doc = new Document(); Iterator iter = news.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); Object key = entry.getKey(); Object val=entry.getValue()==null?"":entry.getValue(); if("FILE_NAME".equals(key.toString().toUpperCase())){ List file=UpInfoService.toMapList(String.valueOf(val)); String textString=""; for(int i=0;i<file.size();i++){ Map map=(Map)file.get(i); textString+=map.get("description").toString(); } val=textString; }else if(val instanceof Date){ doc.add(new StringField(key.toString(),WebUtil.getDate((Date)val,"yyyy-MM-dd HH:mm:ss"), Field.Store.YES));//标题 }else{ doc.add(new StringField(key.toString(),clearHTMLToString(String.valueOf(val)), Field.Store.YES)); } } iw.addDocument(doc); } /** * 读取文件内容为String * @param file * @return String */ public String readFileContent(File file) { try { BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file))); StringBuffer content = new StringBuffer(); for (String line = null; (line = reader.readLine()) != null;) { content.append(line).append("\n"); } return content.toString(); } catch (Exception e) { throw new RuntimeException(e); } } public boolean isEmpty(Object obj){ if(obj==null){ return true; } return "".equals(obj.toString()); } public boolean is(String filed,String ...filds){ for (String string : filds) { if(filed.equalsIgnoreCase(string)){ return true; } } return false; } }
相关推荐
lucene4.7官方完整包
Lucene4.7+IK Analyzer中文分词入门教程
lucene4.7相关jar包 以及IKAnalyzer分词jar包
本案例通过.Net MVC4基础上,针对Lucene.Net实现全文检索的应用。通过查询数据表中数据,创建索引,通过统一输入框进行全文检索。可以进行对索引的增删改查功能。
谷嫂Lucene4.7-Web例子[SpringMVC+MyBatis3],仅供学习参考使用
Lucene 4.7 测试案例,最新版本测试,使用详解
lucene4.7开发实例,包括索引创建、修改、删除、排序、分页、优化、高亮显示、常见几种分词器等。实例加全jar包
lucene4.7所需jar包 IKAnalyzer2012FF 最好的中文分词器
Struts2.3+spring4+hibernate4+Lucene4.7+IKAnalyzer,中文分词,高亮显示,附带MySQL8000条测试数据。仅供学习参考
apache Lucene4.7 最全最新的jar包,很实用,很方便,可以下载后直接导入项目工程中即可。
Lucene 4.7 常用jar集合,官方原始集合太多,传不上来,现精选了一些常用的核心包
本文主要是研究了全文检索技术的基本原理以及Lucene的架构和工作原理,并介绍了基于Lucene的实时全文检索引擎的设计实现过程。并提供了一个基于Web的简单实现。最后通过实验的方式,对实现的实时全文检索引擎的性能...
lucene.net1.4.3全文检索源文件,希望对大家有帮助
Lucene索引工具全套jar包,版本4.7.0
Lucene实现全文检索
Lucene全文检索案例Lucene全文检索案例Lucene全文检索案例Lucene全文检索案例
Lucene4做的全文检索,支持文件和数据库
全文检索的实现:Luene全文索引和数据库索引的比较 中文切分词机制简介:基于词库和自动切分词算法的比较 具体的安装和使用简介:系统结构介绍和演示 Hacking Lucene:简化的查询分析器,删除的实现,定制的排序,...
lucene 4.7版本 可以下载下来使用,而不用自己编写了。自然语言处理,搜索引擎
使用lucene编程实现全文检索数据库内容,程序使用lucene-core-2.4.0以及access数据库