- 浏览: 83793 次
- 性别:
- 来自: 广州
最新评论
-
nanjiwubing123:
头像是java之父。
AJAX中文乱码解决 -
nanjiwubing123:
不错 ,解决了问题。
AJAX中文乱码解决 -
nao000:
感谢您的帖子带给的帮助。
上传文件类型验证工具类 -
KevinGarnett:
这里为什么用\\: 而不是用\: 是因为:是非标准转义字符, ...
jQuery 特殊字符应该使用转义 -
gongmingwind:
写的非常好,多谢多谢
Struts1x项目开发中的统一异常处理
Compass是一流的开放源码JAVA搜索引擎框架,对于你的应用修饰,搜索引擎语义更具有能力。依靠顶级的Lucene搜索引擎,Compass 结合了,像 Hibernate和 Sprin的流行的框架,为你的应用提供了从数据模型和数据源同步改变的搜索力.并且添加了2方面的特征,事物管理和快速更新优化. Compass的目标是:把java应用简单集成到搜索引擎中.编码更少,查找数据更便捷。
这里struts2整合spring、hibernate就不说了。贴出compass+spring+hibernate整合的关键代码。
1、对要检索的实体进行可搜索注解:
2、建索引类
3、Manager
4、compass配置applicationContext-compass.xml
5、因为本实例使用的是庖丁分词,所以添加它的配置文件到src下(paoding-dic-home.properties)
以上就是些关键的配置。
这里struts2整合spring、hibernate就不说了。贴出compass+spring+hibernate整合的关键代码。
1、对要检索的实体进行可搜索注解:
@Searchable public class Product implements java.io.Serializable { @SearchableId private Integer id; @SearchableProperty(name="name") private String name; @SearchableProperty(name="price") private Float price; @SearchableProperty(name="brand") private String brand; @SearchableProperty(name="description") private String description; //getter setter }
2、建索引类
package cn.changtusoft.s2sh_compass.service.impl; import org.compass.gps.CompassGps; import org.springframework.beans.factory.InitializingBean; /** * 通过quartz定时调度定时重建索引或自动随Spring ApplicationContext启动而重建索引的Builder. * 会启动后延时数秒新开线程调用compassGps.index()函数. * 默认会在Web应用每次启动时重建索引,可以设置buildIndex属性为false来禁止此功能. * 也可以不用本Builder, 编写手动调用compassGps.index()的代码. * */ public class CompassIndexBuilder implements InitializingBean { // 是否需要建立索引,可被设置为false使本Builder失效. private boolean buildIndex = false; // 索引操作线程延时启动的时间,单位为秒 private int lazyTime = 10; // Compass封装 private CompassGps compassGps; // 索引线程 private Thread indexThread = new Thread() { @Override public void run() { try { Thread.sleep(lazyTime * 1000); System.out.println("begin compass index..."); long beginTime = System.currentTimeMillis(); // 重建索引. // 如果compass实体中定义的索引文件已存在,索引过程中会建立临时索引, // 索引完成后再进行覆盖. compassGps.index(); long costTime = System.currentTimeMillis() - beginTime; System.out.println("compss index finished."); System.out.println("costed " + costTime + " milliseconds"); } catch (InterruptedException e) { e.printStackTrace(); } } }; /** * 实现<code>InitializingBean</code>接口,在完成注入后调用启动索引线程. * * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() */ public void afterPropertiesSet() throws Exception { if (buildIndex) { indexThread.setDaemon(true); indexThread.setName("Compass Indexer"); indexThread.start(); } } public void setBuildIndex(boolean buildIndex) { this.buildIndex = buildIndex; } public void setLazyTime(int lazyTime) { this.lazyTime = lazyTime; } public void setCompassGps(CompassGps compassGps) { this.compassGps = compassGps; } }
3、Manager
package cn.changtusoft.s2sh_compass.service.impl; import java.util.ArrayList; import java.util.List; import org.compass.core.Compass; import org.compass.core.CompassHits; import org.compass.core.CompassSession; import org.compass.core.CompassTemplate; import org.compass.core.CompassTransaction; import cn.changtusoft.s2sh_compass.dao.ProductDao; import cn.changtusoft.s2sh_compass.model.Product; import cn.changtusoft.s2sh_compass.service.ProductManager; public class ProductManagerImpl implements ProductManager { private ProductDao productDao; private CompassTemplate compassTemplate; @Override public List searchProducts(String description) { List productList = new ArrayList(); Compass compass = compassTemplate.getCompass(); CompassSession session = compass.openSession(); CompassTransaction tx = null; tx = session.beginTransaction(); CompassHits hits = session.queryBuilder().queryString("brand:"+description).toQuery().hits(); for (int i = 0; i < hits.length(); i++) { Product p = (Product)hits.data(i); productList.add(p); } tx.commit(); return productList; } /* setter */ public void setProductDao(ProductDao productDao) { this.productDao = productDao; } public void setCompassTemplate(CompassTemplate compassTemplate) { this.compassTemplate = compassTemplate; } }
4、compass配置applicationContext-compass.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd" default-lazy-init="true"> <bean id="annotationConfiguration" class="org.compass.annotations.config.CompassAnnotationsConfiguration"> </bean> <bean id="compass" class="org.compass.spring.LocalCompassBean"> <property name="resourceDirectoryLocations"> <list> <value>classpath:cn/changtusoft</value> </list> </property> <property name="connection"> <value>/lucene/indexes</value> </property> <property name="classMappings"> <list> <value>cn.changtusoft.s2sh_compass.model.Product</value> </list> </property> <property name="compassConfiguration" ref="annotationConfiguration" /> <property name="compassSettings"> <props> <prop key="compass.transaction.factory"> org.compass.spring.transaction.SpringSyncTransactionFactory </prop> <prop key="compass.engine.analyzer.MMAnalyzer.CustomAnalyzer">net.paoding.analysis.analyzer.PaodingAnalyzer </prop> </props> </property> <property name="transactionManager" ref="transactionManager" /> </bean> <bean id="hibernateGpsDevice" class="org.compass.gps.device.hibernate.HibernateGpsDevice"> <property name="name"> <value>hibernateDevice</value> </property> <property name="sessionFactory" ref="sessionFactory" /> <property name="mirrorDataChanges"> <value>true</value> </property> </bean> <!-- 同步更新索引 --> <bean id="compassGps" class="org.compass.gps.impl.SingleCompassGps" init-method="start" destroy-method="stop"> <property name="compass" ref="compass" /> <property name="gpsDevices"> <list> <bean class="org.compass.spring.device.SpringSyncTransactionGpsDeviceWrapper"> <property name="gpsDevice" ref="hibernateGpsDevice" /> </bean> </list> </property> </bean> <bean id="compassTemplate" class="org.compass.core.CompassTemplate"> <property name="compass" ref="compass" /> </bean> <!-- 定时重建索引(利用quartz)或随Spring ApplicationContext启动而重建索引 --> <bean id="compassIndexBuilder" class="cn.changtusoft.s2sh_compass.service.impl.CompassIndexBuilder" lazy-init="false"> <property name="compassGps" ref="compassGps" /> <property name="buildIndex" value="true" /> <property name="lazyTime" value="10" /> </bean> </beans>
5、因为本实例使用的是庖丁分词,所以添加它的配置文件到src下(paoding-dic-home.properties)
paoding.dic.home=c:/paoding/dic paoding.dic.detector.interval=60
以上就是些关键的配置。
发表评论
-
Java Thread Tech
2015-03-16 00:11 537user thread / daemon threadja ... -
Java Thread Tech
2015-03-16 00:10 0user thread / daemon threadjava ... -
移动支付-微信支付,中国银行支付交互图
2015-03-07 11:30 702以下是自己在做移动支付服务端时,画的支付交互时序图 ... -
OSCache页面缓存应用
2010-02-22 19:29 0OSCache页面缓存应用 -
上传文件类型验证工具类
2010-02-01 16:46 24381、定义合法文件类型的配置文件 allowuploadfil ... -
Tomcat访问地址映射配置
2010-01-08 09:42 4817实现的结果如: http://localhost: ... -
Compass对搜索关键字实现高亮显示
2010-01-07 08:49 1828例如搜"广东",实现后输出结果如 ... -
OSCache 缓存框架使用,方便应用到java开发的网站中
2010-01-05 08:51 2366OSCache标记库由OpenSymphony设计,它是 ... -
assert 是什么?
2010-01-04 00:04 1515assertion(断言)在软件开发中是一种常用的 ... -
struts2+spring+hibernate整合的一些配置文件,方便查找使用
2010-01-01 14:19 2706web.xml <?xml version=&quo ... -
java序列化是什么,如何实现java序列化?
2009-12-30 08:50 1231序列化就是一种用来处理对象流的机制,所谓对象流也就 ... -
J2EE中一些常用的名词
2009-12-29 08:58 857web容器:给处于其中的应用程序组件(JSP,SERVLET) ... -
数据连接池的工作机制
2009-12-28 10:01 1282J2EE服务器启动时会建立一定数量的池连接,并一直 ... -
使用jspSmartUpload轻松实现上传和下载
2009-11-05 09:06 1133jspSmartUpload是由www.jspsm ... -
Struts2与Struts1的对比(推荐)
2009-11-03 22:24 7361、Action 类: Struts1要 ... -
定好项目规范的重要性
2009-11-02 23:28 1064近几个月都在忙于一个项目,由于需求的不明确,开始做的时 ... -
优秀java开源论坛 JForum,轻松搭建自己的论坛
2009-09-30 11:49 1480JForum 是一个功能强大 ,易于管理的论坛。它的 ... -
FreeMarker中文学习笔记
2009-09-24 17:09 715FreeMarker中文学习笔记。 -
多条件搜索的抽象实现
2009-09-24 17:02 0ColumnFields ColumnField -
Hibernate OneToOne双向关联为什么没有外键的一方不能Lazy加载?
2009-08-25 21:08 1665关联关系映射通常情况是比较难配置正确的。我觉得真正要掌握 ...
相关推荐
struts2+spring3+hibernate3+compass实现全文检索功能,希望对初学者有所帮助!
struts2 hibernate spring compass全文检索,采用的是ssh2+compass来实现,本项目没有采用lunce,compass and lunce之间的哪个好用比一下就知道
struts2-spring-compass Struts2整合Spring3、Hibernate、Compass实现全文检索(基于lucene2.4.1和极易中文分词器)
使用compass+lucene实现简单的全文...里面整合了spring2.5、hibernate3.2、struts2.0,是对数据库进行全文检索的一个非常好的demo的所有jar包组合! 对研究基于数据库检索的java开源搜索引擎的朋友有很大的参考价值
用Compass提供的Spring2 Schema 来配置Compass与Hibernate,Spring的结合。 SchemaBase的配置是Spring 2.0的新特征,相比原来的配置代码要少一些。 3.编写搜索结果显示页,将Hits,Command,Page三个变量显示出来。 ...
是一个全文检索引擎的架构,提供了完整的查询引擎和索引引擎 json-lib-2.2.3-jdk15.jar json和java转化的辅助工具 flexjson.jar java到json串的转换 gson-1.3.jar java到json串的转换 ognl-2.6.11.jar...
是一个全文检索引擎的架构,提供了完整的查询引擎和索引引擎 json-lib-2.2.3-jdk15.jar json和java转化的辅助工具 flexjson.jar java到json串的转换 gson-1.3.jar java到json串的转换 ognl-2.6.11.jar OGNL...
JCaptcha4Struts2 是一个 Struts2的插件,用来增加验证码的支持,使用时只需要用一个 JSP 标签 (<jcaptcha:image label="Type the text "/> ) 即可,直接在 struts.xml 中进行配置,使用强大的 JCaptcha来生成验证码...
JCaptcha4Struts2 是一个 Struts2的插件,用来增加验证码的支持,使用时只需要用一个 JSP 标签 (<jcaptcha:image label="Type the text "/> ) 即可,直接在 struts.xml 中进行配置,使用强大的 JCaptcha来生成验证码...
JCaptcha4Struts2 是一个 Struts2的插件,用来增加验证码的支持,使用时只需要用一个 JSP 标签 (<jcaptcha:image label="Type the text "/> ) 即可,直接在 struts.xml 中进行配置,使用强大的 JCaptcha来生成验证码...
2个目标文件,FTP的目标是:(1)提高文件的共享性(计算机程序和/或数据),(2)鼓励间接地(通过程序)使用远程计算机,(3)保护用户因主机之间的文件存储系统导致的变化,(4)为了可靠和高效地传输,虽然用户...
2个目标文件,FTP的目标是:(1)提高文件的共享性(计算机程序和/或数据),(2)鼓励间接地(通过程序)使用远程计算机,(3)保护用户因主机之间的文件存储系统导致的变化,(4)为了可靠和高效地传输,虽然用户...
JCaptcha4Struts2 是一个 Struts2的插件,用来增加验证码的支持,使用时只需要用一个 JSP 标签 (<jcaptcha:image label="Type the text "/> ) 即可,直接在 struts.xml 中进行配置,使用强大的 JCaptcha来生成验证码...
JCaptcha4Struts2 是一个 Struts2的插件,用来增加验证码的支持,使用时只需要用一个 JSP 标签 (<jcaptcha:image label="Type the text "/> ) 即可,直接在 struts.xml 中进行配置,使用强大的 JCaptcha来生成验证码...
JCaptcha4Struts2 是一个 Struts2的插件,用来增加验证码的支持,使用时只需要用一个 JSP 标签 (<jcaptcha:image label="Type the text "/> ) 即可,直接在 struts.xml 中进行配置,使用强大的 JCaptcha来生成验证码...
JCaptcha4Struts2 是一个 Struts2的插件,用来增加验证码的支持,使用时只需要用一个 JSP 标签 (<jcaptcha:image label="Type the text "/> ) 即可,直接在 struts.xml 中进行配置,使用强大的 JCaptcha来生成验证码...
JCaptcha4Struts2 是一个 Struts2的插件,用来增加验证码的支持,使用时只需要用一个 JSP 标签 (<jcaptcha:image label="Type the text "/> ) 即可,直接在 struts.xml 中进行配置,使用强大的 JCaptcha来生成验证码...
JCaptcha4Struts2 是一个 Struts2的插件,用来增加验证码的支持,使用时只需要用一个 JSP 标签 (<jcaptcha:image label="Type the text "/> ) 即可,直接在 struts.xml 中进行配置,使用强大的 JCaptcha来生成验证码...
JCaptcha4Struts2 是一个 Struts2的插件,用来增加验证码的支持,使用时只需要用一个 JSP 标签 (<jcaptcha:image label="Type the text "/> ) 即可,直接在 struts.xml 中进行配置,使用强大的 JCaptcha来生成验证码...