- 浏览: 851984 次
文章分类
- 全部博客 (365)
- java (124)
- spring mvc (21)
- spring (22)
- struts2 (6)
- jquery (27)
- javascript (24)
- mybatis/ibatis (8)
- hibernate (7)
- compass (11)
- lucene (26)
- flex (0)
- actionscript (0)
- webservice (8)
- rabbitMQ/Socket (15)
- jsp/freemaker (5)
- 数据库 (27)
- 应用服务器 (21)
- Hadoop (1)
- PowerDesigner (3)
- EJB (0)
- JPA (0)
- PHP (2)
- C# (0)
- .NET (0)
- html (2)
- xml (5)
- android (7)
- flume (1)
- zookeeper (0)
- 证书加密 (2)
- maven (1)
- redis (2)
- cas (11)
最新评论
-
zuxianghuang:
通过pom上传报错 Artifact upload faile ...
nexus上传了jar包.通过maven引用当前jar,不能取得jar的依赖 -
流年末年:
百度网盘的挂了吧???
SSO单点登录系列3:cas-server端配置认证方式实践(数据源+自定义java类认证) -
953434367:
UfgovDBUtil 是什么类
Java发HTTP POST请求(内容为xml格式) -
smilease:
帮大忙了,非常感谢
freemaker自动生成源代码 -
syd505:
十分感谢作者无私的分享,仔细阅读后很多地方得以解惑。
Nginx 反向代理、负载均衡、页面缓存、URL重写及读写分离详解
目录
四、使用流程: …………………………………………………………………………………….
五、基于SSH的compass的实例: …………………………………………………………………
一、原理描述:
Compass是一流的开放源码JAVA搜索引擎框架,对于你的应用修饰,搜索引擎语义更具有能力。依靠顶级的Lucene搜索引擎,Compass 结合了,像 Hibernate和 Spring的流行的框架,为你的应用提供了从数据模型和数据源同步改变的搜索力.并且添加了2方面的特征,事物管理和快速更新优化.
Compass的目标是:把java应用简单集成到搜索引擎中.编码更少,查找数据更便捷 .
二、术语解释:
名称 |
描述 |
Lucene |
Apache Lucene是一个基于Java全文搜索引擎,利用它可以轻易地为Java软件加入全文搜寻功能。Lucene的最主要工作是替文件的每一个字作索引,索引让搜寻的效率比传统的逐字比较大大提高了,Lucene提供一组解读,过滤,分析文件,编排和使用索引的提供一组解读,过滤,分析文件,编排和使用索引的API,它的强大之处除了高效和简单外,是最重要的是使使用都是可以随时应自己需要自订其功能。开发者可以把Lucene看成一个支持全文索引的数据库系统的. |
Compass |
我对Compass的定义是面向域模型的搜索框架, 面向域模型意味着必须支持对对象的搜索,对持久化对象的搜索,和对XML文档对象的搜索,同时还必须支持事务的处理,包括对创建,更新,保存,删除进行事务级别的处理. 所以, Compass是基于Lucene, 高于Lucene的. 有个形象的比喻. Compass对于Lucene就像Hibernate对于JDBC,太有才了!Compass的开发路数完全参照Hibernate. |
OSEM |
对象搜索引擎影射(Object Search Engine Mapping),通过xml配置文件,提供了POJO's (Plain Old Java Objects)到搜索引擎. |
三、下载地址:
软件名称 |
下载地址 |
软件描述 |
Compass框架、jar包 |
http://www.compassframework.org/ |
基于Java的搜索引擎 |
四、使用流程:
网络机器人程序 www文档 网络机器人程序 建立索引 从数据库中搜索信息 Tomcat服务器 JSP 索引数据库 浏览器 浏览器
五、基于SSH的compass的实例:
step1
在ssh2的基础上开发 加入jar包(compass-2.1.2.jar compass-index-patch.jar
lucene-analyzers-2.4.0.jar lucene-core-2.4.0.jar lucene-highlighter-2.4.0.jar paoding-analysis.jar
)
step2
先来看下实体bean的编写
- package com.v512.example.model;
- import org.compass.annotations.*;
- /**
- * Product entity.
- *
- * @author MyEclipse Persistence Tools
- */
- @Searchable
- public class Product implements java.io.Serializable {
- // Fields
- @SearchableId
- private String id;
- @SearchableProperty(name="name",index=Index.ANALYZED,store=Store.YES)
- private String name;
- @SearchableProperty(name="price",index=Index.NOT_ANALYZED,store=Store.YES)
- private Double price;
- @SearchableProperty(name="brand",index=Index.ANALYZED,store=Store.YES)
- private String brand;
- @SearchableProperty(name="description",index=Index.ANALYZED,store=Store.YES)
- private String description;
- // Constructors
- /** default constructor */
- public Product() {
- }
- /** full constructor */
- public Product(String name, Double price, String brand, String description) {
- this.name = name;
- this.price = price;
- this.brand = brand;
- this.description = description;
- }
- // Property accessors
- public String getId() {
- return this.id;
- }
- public void setId(String id) {
- this.id = id;
- }
- public String getName() {
- return this.name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public Double getPrice() {
- return this.price;
- }
- public void setPrice(Double price) {
- this.price = price;
- }
- public String getBrand() {
- return this.brand;
- }
- public void setBrand(String brand) {
- this.brand = brand;
- }
- public String getDescription() {
- return this.description;
- }
- public void setDescription(String description) {
- this.description = description;
- }
- }
package com.v512.example.model;
import org.compass.annotations.*;
/**
* Product entity.
*
* @author MyEclipse Persistence Tools
*/
@Searchable
public class Product implements java.io.Serializable {
// Fields
@SearchableId
private String id;
@SearchableProperty(name="name",index=Index.ANALYZED,store=Store.YES)
private String name;
@SearchableProperty(name="price",index=Index.NOT_ANALYZED,store=Store.YES)
private Double price;
@SearchableProperty(name="brand",index=Index.ANALYZED,store=Store.YES)
private String brand;
@SearchableProperty(name="description",index=Index.ANALYZED,store=Store.YES)
private String description;
// Constructors
/** default constructor */
public Product() {
}
/** full constructor */
public Product(String name, Double price, String brand, String description) {
this.name = name;
this.price = price;
this.brand = brand;
this.description = description;
}
// Property accessors
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public Double getPrice() {
return this.price;
}
public void setPrice(Double price) {
this.price = price;
}
public String getBrand() {
return this.brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
}
step3属性文件Product.hbm.xml
- <?xml version="1.0" encoding="utf-8"?>
- <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
- <!--
- Mapping file autogenerated by MyEclipse Persistence Tools
- -->
- <hibernate-mapping>
- <class name="com.v512.example.model.Product" table="PRODUCT" >
- <id name="id" type="java.lang.String">
- <column name="ID" length="40" />
- <generator class="uuid.hex" />
- </id>
- <property name="name" type="java.lang.String">
- <column name="NAME" length="80" />
- </property>
- <property name="price" type="java.lang.Double">
- <column name="PRICE" precision="6" />
- </property>
- <property name="brand" type="java.lang.String">
- <column name="BRAND" length="40" />
- </property>
- <property name="description" type="java.lang.String">
- <column name="DESCRIPTION" length="2000" />
- </property>
- </class>
- </hibernate-mapping>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.v512.example.model.Product" table="PRODUCT" >
<id name="id" type="java.lang.String">
<column name="ID" length="40" />
<generator class="uuid.hex" />
</id>
<property name="name" type="java.lang.String">
<column name="NAME" length="80" />
</property>
<property name="price" type="java.lang.Double">
<column name="PRICE" precision="6" />
</property>
<property name="brand" type="java.lang.String">
<column name="BRAND" length="40" />
</property>
<property name="description" type="java.lang.String">
<column name="DESCRIPTION" length="2000" />
</property>
</class>
</hibernate-mapping>
要使用Compass必须加入一个applicationContext-compass.xml文件,文件名可以自行定义这个就不用说了 废话
step4applicationContext-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">
- <!-- 配置compass的注解功能 -->
- <bean id="annotationConfiguration"
- class="org.compass.annotations.config.CompassAnnotationsConfiguration">
- </bean>
- <bean id="compass" class="org.compass.spring.LocalCompassBean">
- <!-- 配置需要索引的实体映射文件的路径 -->
- <property name="resourceDirectoryLocations">
- <list>
- <value>classpath:com/v512/example/model</value>
- </list>
- </property>
- <!-- 设置存放索引的路径 -->
- <property name="connection">
- <value>/lucene/indexes</value>
- </property>
- <!--配置要搜索的类,作用:会根据以下的类建立索引 -->
- <property name="classMappings">
- <list>
- <value>com.v512.example.model.Product</value>
- </list>
- </property>
- <property name="compassConfiguration"
- ref="annotationConfiguration" />
- <!--compass的一些属性设置 -->
- <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>
- <!--compass的事务管理器 -->
- <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="com.v512.example.service.impl.CompassIndexBuilder"
- lazy-init="false">
- <property name="compassGps" ref="compassGps" />
- <property name="buildIndex" value="true" />
- <property name="lazyTime" value="10" />
- </bean>
- </beans>
<?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">
<!-- 配置compass的注解功能 -->
<bean id="annotationConfiguration"
class="org.compass.annotations.config.CompassAnnotationsConfiguration">
</bean>
<bean id="compass" class="org.compass.spring.LocalCompassBean">
<!-- 配置需要索引的实体映射文件的路径 -->
<property name="resourceDirectoryLocations">
<list>
<value>classpath:com/v512/example/model</value>
</list>
</property>
<!-- 设置存放索引的路径 -->
<property name="connection">
<value>/lucene/indexes</value>
</property>
<!--配置要搜索的类,作用:会根据以下的类建立索引 -->
<property name="classMappings">
<list>
<value>com.v512.example.model.Product</value>
</list>
</property>
<property name="compassConfiguration"
ref="annotationConfiguration" />
<!--compass的一些属性设置 -->
<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>
<!--compass的事务管理器 -->
<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="com.v512.example.service.impl.CompassIndexBuilder"
lazy-init="false">
<property name="compassGps" ref="compassGps" />
<property name="buildIndex" value="true" />
<property name="lazyTime" value="10" />
</bean>
</beans>
中间都有注解 就不多解释了
下面来编写dao及dao的实现以及severce层
step5
- package com.v512.example.dao;
- import java.util.List;
- import com.v512.example.model.Product;
- public interface ProductDao {
- public void create(Product p);
- public Product getProduct(String id);
- public List getProducts();
- public void update(Product product);
- public void remove(String id);
- }
package com.v512.example.dao;
import java.util.List;
import com.v512.example.model.Product;
public interface ProductDao {
public void create(Product p);
public Product getProduct(String id);
public List getProducts();
public void update(Product product);
public void remove(String id);
}
- package com.v512.example.dao.hibernate;
- import java.util.List;
- import com.v512.example.dao.ProductDao;
- import com.v512.example.model.Product;
- import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
- public class ProductDaoHibernate extends HibernateDaoSupport implements ProductDao {
- public void create(Product p) {
- getHibernateTemplate().save(p);
- }
- public Product getProduct(String id) {
- return (Product)getHibernateTemplate().get(Product.class, id);
- }
- public List getProducts() {
- return getHibernateTemplate().find("from Product order by id desc");
- }
- public void remove(String id) {
- getHibernateTemplate().delete(getProduct(id));
- }
- public void update(Product product) {
- getHibernateTemplate().saveOrUpdate(product);
- }
- }
package com.v512.example.dao.hibernate;
import java.util.List;
import com.v512.example.dao.ProductDao;
import com.v512.example.model.Product;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public class ProductDaoHibernate extends HibernateDaoSupport implements ProductDao {
public void create(Product p) {
getHibernateTemplate().save(p);
}
public Product getProduct(String id) {
return (Product)getHibernateTemplate().get(Product.class, id);
}
public List getProducts() {
return getHibernateTemplate().find("from Product order by id desc");
}
public void remove(String id) {
getHibernateTemplate().delete(getProduct(id));
}
public void update(Product product) {
getHibernateTemplate().saveOrUpdate(product);
}
}
servece
- package com.v512.example.service;
- import java.util.List;
- import com.v512.example.model.Product;
- public interface ProductManager {
- public void insertProduct(Product p);
- public Product findProdcut(String id);
- public List searchProducts(String queryString);
- }
package com.v512.example.service;
import java.util.List;
import com.v512.example.model.Product;
public interface ProductManager {
public void insertProduct(Product p);
public Product findProdcut(String id);
public List searchProducts(String queryString);
}
servece的实现
- package com.v512.example.service.impl;
- import java.util.ArrayList;
- import java.util.List;
- import org.compass.core.CompassHits;
- import org.compass.core.CompassSession;
- import org.compass.core.CompassTemplate;
- import org.compass.core.CompassTransaction;
- import com.v512.example.dao.ProductDao;
- import com.v512.example.model.Product;
- import com.v512.example.service.ProductManager;
- import org.compass.core.Compass;
- public class ProductManagerImpl implements ProductManager {
- private ProductDao productDao;
- private CompassTemplate compassTemplate;
- public void setCompassTemplate(CompassTemplate compassTemplate){
- this.compassTemplate=compassTemplate;
- }
- public void setProductDao(ProductDao productDao){
- this.productDao=productDao;
- }
- public Product findProdcut(String id) {
- return productDao.getProduct(id);
- }
- public void insertProduct(Product p) {
- productDao.create(p);
- }
- public List searchProducts(String queryString) {
- Compass compass = compassTemplate.getCompass();
- CompassSession session=compass.openSession();
- List list = new ArrayList();
- //这里不需要开启事务了,因为在调用这个方法之前就已经开启了事务
- CompassHits hits= session.queryBuilder().queryString("name:"+queryString).toQuery().hits();
- System.out.println("queryString:"+queryString);
- System.out.println("hits:"+hits.getLength());
- for(int i=0;i<hits.length();i++){
- Product hit=(Product)hits.data(i);
- list.add(hit);
- }
- return list;
- }
- public CompassTemplate getCompassTemplate() {
- return compassTemplate;
- }
- }
package com.v512.example.service.impl;
import java.util.ArrayList;
import java.util.List;
import org.compass.core.CompassHits;
import org.compass.core.CompassSession;
import org.compass.core.CompassTemplate;
import org.compass.core.CompassTransaction;
import com.v512.example.dao.ProductDao;
import com.v512.example.model.Product;
import com.v512.example.service.ProductManager;
import org.compass.core.Compass;
public class ProductManagerImpl implements ProductManager {
private ProductDao productDao;
private CompassTemplate compassTemplate;
public void setCompassTemplate(CompassTemplate compassTemplate){
this.compassTemplate=compassTemplate;
}
public void setProductDao(ProductDao productDao){
this.productDao=productDao;
}
public Product findProdcut(String id) {
return productDao.getProduct(id);
}
public void insertProduct(Product p) {
productDao.create(p);
}
public List searchProducts(String queryString) {
Compass compass = compassTemplate.getCompass();
CompassSession session=compass.openSession();
List list = new ArrayList();
//这里不需要开启事务了,因为在调用这个方法之前就已经开启了事务
CompassHits hits= session.queryBuilder().queryString("name:"+queryString).toQuery().hits();
System.out.println("queryString:"+queryString);
System.out.println("hits:"+hits.getLength());
for(int i=0;i<hits.length();i++){
Product hit=(Product)hits.data(i);
list.add(hit);
}
return list;
}
public CompassTemplate getCompassTemplate() {
return compassTemplate;
}
}
所有的都做完了
现在编写jsp页面
step6
insertProduct.jsp
- <%@ page language="java" contentType="text/html; charset=UTF-8"
- pageEncoding="UTF-8"%>
- <%@ taglib prefix="s" uri="/struts-tags"%>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <link href="style/oa.css" rel="stylesheet" type="text/css">
- <title>添加信息</title>
- </head>
- <body>
- <center>
- <s:form action="insert.action" theme="simple">
- <TABLE class="tableEdit" border="0" cellspacing="1" cellpadding="0" style="width:300px;">
- <TBODY>
- <TR>
- <td align="center" class="tdEditTitle">添加商品名称</TD>
- </TR>
- <TR>
- <td>
- <table class="tableEdit" style="width:300px;" cellspacing="0" border="0" cellpadding="0">
- <tr>
- <td class="tdEditLabel" >商品名称</td>
- <td class="tdEditContent"><s:textfield name="product.name" label="名称" /></td>
- </tr>
- <tr>
- <td class="tdEditLabel" >商品品牌</td>
- <td class="tdEditContent"><s:textfield name="product.brand" label="品牌" /></td>
- </tr>
- <tr>
- <td class="tdEditLabel" >商品价格</td>
- <td class="tdEditContent"><s:textfield name="product.price" label="价格" /></td>
- </tr>
- <tr>
- <td class="tdEditLabel" >商品描述</td>
- <td class="tdEditContent"><s:textarea name="product.description" label="描述" />
- </td>
- </tr>
- <tr>
- <td>
- </td>
- <td><s:submit/>
- <br></td>
- </tr>
- </table>
- </td>
- </TR>
- </TBODY>
- </TABLE>
- </s:form>
- </center>
- </body>
- </html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="style/oa.css" rel="stylesheet" type="text/css">
<title>添加信息</title>
</head>
<body>
<center>
<s:form action="insert.action" theme="simple">
<TABLE class="tableEdit" border="0" cellspacing="1" cellpadding="0" style="width:300px;">
<TBODY>
<TR>
<td align="center" class="tdEditTitle">添加商品名称</TD>
</TR>
<TR>
<td>
<table class="tableEdit" style="width:300px;" cellspacing="0" border="0" cellpadding="0">
<tr>
<td class="tdEditLabel" >商品名称</td>
<td class="tdEditContent"><s:textfield name="product.name" label="名称" /></td>
</tr>
<tr>
<td class="tdEditLabel" >商品品牌</td>
<td class="tdEditContent"><s:textfield name="product.brand" label="品牌" /></td>
</tr>
<tr>
<td class="tdEditLabel" >商品价格</td>
<td class="tdEditContent"><s:textfield name="product.price" label="价格" /></td>
</tr>
<tr>
<td class="tdEditLabel" >商品描述</td>
<td class="tdEditContent"><s:textarea name="product.description" label="描述" />
</td>
</tr>
<tr>
<td>
</td>
<td><s:submit/>
<br></td>
</tr>
</table>
</td>
</TR>
</TBODY>
</TABLE>
</s:form>
</center>
</body>
</html>
step7
编写action
- package com.v512.example.action;
- import java.util.List;
- import com.opensymphony.xwork2.ActionSupport;
- import com.v512.example.model.Product;
- import com.v512.example.service.ProductManager;
- import org.apache.struts2.ServletActionContext;
- public class ProductAction extends ActionSupport {
- private static final long serialVersionUID = 3795048906805728732L;
- private ProductManager productManager;
- private Product product;
- private String queryString;
- public void setQueryString(String queryString){
- this.queryString=queryString;
- }
- public Product getProduct() {
- return product;
- }
- public void setProduct(Product product) {
- this.product = product;
- }
- public void setProductManager(ProductManager productManager){
- this.productManager=productManager;
- }
- public String insert(){
- productManager.insertProduct(product);
- return SUCCESS;
- }
- public String search(){
- List results=productManager.searchProducts(queryString);
- System.out.println(results.size());
- ServletActionContext.getRequest().setAttribute("searchresults", results);
- return SUCCESS;
- }
- }
package com.v512.example.action;
import java.util.List;
import com.opensymphony.xwork2.ActionSupport;
import com.v512.example.model.Product;
import com.v512.example.service.ProductManager;
import org.apache.struts2.ServletActionContext;
public class ProductAction extends ActionSupport {
private static final long serialVersionUID = 3795048906805728732L;
private ProductManager productManager;
private Product product;
private String queryString;
public void setQueryString(String queryString){
this.queryString=queryString;
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public void setProductManager(ProductManager productManager){
this.productManager=productManager;
}
public String insert(){
productManager.insertProduct(product);
return SUCCESS;
}
public String search(){
List results=productManager.searchProducts(queryString);
System.out.println(results.size());
ServletActionContext.getRequest().setAttribute("searchresults", results);
return SUCCESS;
}
}
step8关于Struts2的配置文件如下
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE struts PUBLIC
- "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
- "http://struts.apache.org/dtds/struts-2.0.dtd">
- <struts>
- <constant name="struts.objectFactory" value="spring" />
- <include file="struts-default.xml"/>
- <package name="product" extends="struts-default"
- namespace="/product">
- <!-- 配置Struts2的Action,class值要与applicationContext*.xml中的id的值一致。 -->
- <action name="insert"
- class="productBean" method="insert">
- <result >insertOk.jsp</result>
- </action>
- <action name="search"
- class="productBean" method="search">
- <result >searchResults.jsp</result>
- </action>
- </package>
- </struts>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.objectFactory" value="spring" />
<include file="struts-default.xml"/>
<package name="product" extends="struts-default"
namespace="/product">
<!-- 配置Struts2的Action,class值要与applicationContext*.xml中的id的值一致。 -->
<action name="insert"
class="productBean" method="insert">
<result >insertOk.jsp</result>
</action>
<action name="search"
class="productBean" method="search">
<result >searchResults.jsp</result>
</action>
</package>
</struts>
如果插入成功就跳转到insertOk。jsp
- <%@ page language="java" contentType="text/html; charset=UTF-8"
- pageEncoding="UTF-8"%>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Insert title here</title>
- </head>
- <body>
- 添加商品成功!
- </body>
- </html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
添加商品成功!
</body>
</html>
step9到此所有准备工作都做完了
下面来看下 spring的配置文件applicationContext.xml 和web.xml
web.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app version="2.5"
- xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
- http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
- <!--定义Spring的配置的位置,可以定义多个配置文件,可以使用通配符。 -->
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>/WEB-INF/applicationContext*.xml</param-value>
- </context-param>
- <!--设置一起动当前的Web应用,就加载Spring,让Spring管理Bean-->
- <listener>
- <listener-class>
- org.springframework.web.context.ContextLoaderListener
- </listener-class>
- </listener>
- <!--解决Hibernate延迟加载出现的问题,需要放到struts2过滤器之前-->
- <filter>
- <filter-name>lazyLoadingFilter</filter-name>
- <filter-class>
- org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
- </filter-class>
- </filter>
- <!--Struts2的过滤器,使用Struts2,必须配置该项-->
- <filter>
- <filter-name>struts2</filter-name>
- <filter-class>
- org.apache.struts2.dispatcher.FilterDispatcher
- </filter-class>
- </filter>
- <!--解决Hibernate延迟加载出现的问题,仍需要放到struts2过滤器mapping之前-->
- <filter-mapping>
- <filter-name>lazyLoadingFilter</filter-name>
- <url-pattern>*.action</url-pattern>
- </filter-mapping>
- <!--Struts2的过滤器,配套的filter-mapping-->
- <filter-mapping>
- <filter-name>struts2</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- </web-app>
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!--定义Spring的配置的位置,可以定义多个配置文件,可以使用通配符。 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>
<!--设置一起动当前的Web应用,就加载Spring,让Spring管理Bean-->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!--解决Hibernate延迟加载出现的问题,需要放到struts2过滤器之前-->
<filter>
<filter-name>lazyLoadingFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<!--Struts2的过滤器,使用Struts2,必须配置该项-->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<!--解决Hibernate延迟加载出现的问题,仍需要放到struts2过滤器mapping之前-->
<filter-mapping>
<filter-name>lazyLoadingFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<!--Struts2的过滤器,配套的filter-mapping-->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
applicationContext.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"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop-2.5.xsd" default-lazy-init="true">
- <!-- mysql数据库 :定义数据源的Bean ,给Hibernate的sessionFactory -->
- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
- <property name="driverClassName" value="org.gjt.mm.mysql.Driver"/>
- <property name="url" value="jdbc:mysql://localhost:3306/ssh2compass?useUnicode=true&characterEncoding=UTF-8"/>
- <property name="username" value="root"/>
- <property name="password" value="123456"/>
- <!-- 连接池启动时的初始值 -->
- <property name="initialSize" value="1"/>
- <!-- 连接池的最大值 -->
- <property name="maxActive" value="500"/>
- <!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 -->
- <property name="maxIdle" value="2"/>
- <!-- 最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 -->
- <property name="minIdle" value="1"/>
- </bean>
- <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
- <property name="dataSource" ref="dataSource"/>
- <property name="mappingResources">
- <list>
- <value>com/v512/example/model/Product.hbm.xml</value>
- </list>
- </property>
- <property name="hibernateProperties">
- <value>
- hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
- hibernate.hbm2ddl.auto=update
- hibernate.show_sql=false
- hibernate.format_sql=false
- hibernate.cache.use_second_level_cache=true
- hibernate.cache.use_query_cache=false
- hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
- </value>
- </property>
- </bean>
- <!-- oracle数据库 :定义数据源的Bean ,给Hibernate的sessionFactory-->
- <!--
- <bean id="dataSource"
- class="org.apache.commons.dbcp.BasicDataSource">
- <property name="driverClassName"
- value="oracle.jdbc.driver.OracleDriver">
- </property>
- <property name="url"
- value="jdbc:oracle:thin:@192.168.1.3:1521:ora9">
- </property>
- <property name="username" value="scott"></property>
- <property name="password" value="tiger"></property>
- </bean>
- -->
- <!-- 定义Hibernate的sessionFactory,通过该Bean,可以获得Hibernate的Session-->
- <!--
- <bean id="sessionFactory"
- class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
- <property name="dataSource">
- <ref bean="dataSource" />
- </property>
- <property name="hibernateProperties">
- <props>
- <prop key="hibernate.dialect">
- org.hibernate.dialect.Oracle9Dialect
- </prop>
- <prop key="hibernate.cache.provider_class">
- org.hibernate.cache.EhCacheProvider
- </prop>
- <prop key="hibernate.cache.use_query_cache">true</prop>
- <prop key="hibernate.show_sql">true</prop>
- </props>
- </property>
- <property name="mappingResources">
- <list>
- <value>
- com/v512/example/model/Product.hbm.xml
- </value>
- </list>
- </property>
- </bean>
- -->
- <bean id="productDao" class="com.v512.example.dao.hibernate.ProductDaoHibernate">
- <property name="sessionFactory" ref="sessionFactory"></property>
- </bean>
- <bean id="productManager" class="com.v512.example.service.impl.ProductManagerImpl">
- <property name="productDao" ref="productDao"></property>
- <property name="compassTemplate" ref="compassTemplate"></property>
- </bean>
- <bean id="productBean" class="com.v512.example.action.ProductAction" scope="prototype">
- <property name="productManager" ref="productManager"></property>
- </bean>
- <!-- 配置事务管理器 -->
- <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
- <property name="sessionFactory">
- <ref local="sessionFactory"/>
- </property>
- </bean>
- <!-- 配置事务特性 ,配置add、delete和update开始的方法,事务传播特性为required-->
- <tx:advice id="txAdvice" transaction-manager="transactionManager">
- <tx:attributes>
- <tx:method name="insert*" propagation="REQUIRED"/>
- <tx:method name="delete*" propagation="REQUIRED"/>
- <tx:method name="update*" propagation="REQUIRED"/>
- <tx:method name="*" read-only="true"/>
- </tx:attributes>
- </tx:advice>
- <!-- 配置那些类的方法进行事务管理,当前cn.com.jobedu.oa.service包中的子包、类中所有方法需要,还需要参考tx:advice的设置 -->
- <aop:config>
- <aop:pointcut id="allManagerMethod" expression="execution (* com.v512.example.service.*.*(..))"/>
- <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>
- </aop:config>
- </beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd" default-lazy-init="true">
<!-- mysql数据库 :定义数据源的Bean ,给Hibernate的sessionFactory -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="org.gjt.mm.mysql.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/ssh2compass?useUnicode=true&characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value="123456"/>
<!-- 连接池启动时的初始值 -->
<property name="initialSize" value="1"/>
<!-- 连接池的最大值 -->
<property name="maxActive" value="500"/>
<!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 -->
<property name="maxIdle" value="2"/>
<!-- 最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 -->
<property name="minIdle" value="1"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
<value>com/v512/example/model/Product.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.hbm2ddl.auto=update
hibernate.show_sql=false
hibernate.format_sql=false
hibernate.cache.use_second_level_cache=true
hibernate.cache.use_query_cache=false
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
</value>
</property>
</bean>
<!-- oracle数据库 :定义数据源的Bean ,给Hibernate的sessionFactory-->
<!--
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="url"
value="jdbc:oracle:thin:@192.168.1.3:1521:ora9">
</property>
<property name="username" value="scott"></property>
<property name="password" value="tiger"></property>
</bean>
-->
<!-- 定义Hibernate的sessionFactory,通过该Bean,可以获得Hibernate的Session-->
<!--
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
<prop key="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>
com/v512/example/model/Product.hbm.xml
</value>
</list>
</property>
</bean>
-->
<bean id="productDao" class="com.v512.example.dao.hibernate.ProductDaoHibernate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="productManager" class="com.v512.example.service.impl.ProductManagerImpl">
<property name="productDao" ref="productDao"></property>
<property name="compassTemplate" ref="compassTemplate"></property>
</bean>
<bean id="productBean" class="com.v512.example.action.ProductAction" scope="prototype">
<property name="productManager" ref="productManager"></property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<!-- 配置事务特性 ,配置add、delete和update开始的方法,事务传播特性为required-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 配置那些类的方法进行事务管理,当前cn.com.jobedu.oa.service包中的子包、类中所有方法需要,还需要参考tx:advice的设置 -->
<aop:config>
<aop:pointcut id="allManagerMethod" expression="execution (* com.v512.example.service.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>
</aop:config>
</beans>
到此已经可以测试了
测试完插入之后,所有准备工作都已完成 现在我们来测下搜索
search.jap
- <%@ page language="java" contentType="text/html; charset=UTF-8"
- pageEncoding="UTF-8"%>
- <%@taglib prefix="s" uri="/struts-tags" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Insert title here</title>
- </head>
- <body>
- <s:form action="search.action" method="post">
- <s:textfield name="queryString" label="搜索产品"/>
- <s:submit></s:submit>
- </s:form>
- </body>
- </html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<s:form action="search.action" method="post">
<s:textfield name="queryString" label="搜索产品"/>
<s:submit></s:submit>
</s:form>
</body>
</html>
搜索后的结果页面
searchResults.jsp
- <%@ page language="java" contentType="text/html; charset=UTF-8"
- import="java.util.List"
- pageEncoding="UTF-8"%>
- <%@taglib prefix="s" uri="/struts-tags" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Insert title here</title>
- </head>
- <body>
- <%
- if(((List)request.getAttribute("searchresults")).size()==0){
- %>
- no results found.
- <%} %>
- <table border="1">
- <s:iterator value="#request.searchresults">
- <tr><td>
- <s:property value="name"/>
- </td>
- <td>
- <s:property value="price"/></td>
- <td>
- <s:property value="brand"/></td>
- <td>
- <s:property value="description"/></td>
- </tr>
- </s:iterator>
- </table>
- </body>
- </html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
import="java.util.List"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
if(((List)request.getAttribute("searchresults")).size()==0){
%>
no results found.
<%} %>
<table border="1">
<s:iterator value="#request.searchresults">
<tr><td>
<s:property value="name"/>
</td>
<td>
<s:property value="price"/></td>
<td>
<s:property value="brand"/></td>
<td>
<s:property value="description"/></td>
</tr>
</s:iterator>
</table>
</body>
</html>
step10
另外得说下,该项目见索引的过程:服务器启动把需要建立索引的表的数据全部取出建立索引
在项目运行过程中,插入数据,容器检测到索引有变动,添加索引,这个可以自己测试
为此 要添加另外一个类:该类就是专门建索引用 注意包的位置
CompassIndexBuilder
- package com.v512.example.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;
- }
- }
package com.v512.example.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;
}
}
本项目中用的是paoding-analyzer
所以请在src目录下增加paoding-dic-home.properties文件
- paoding.dic.home=C:/paoding/dic
- paoding.dic.detector.interval=60
paoding.dic.home=C:/paoding/dic
paoding.dic.detector.interval=60
over
发表评论
-
solr第一弹 autocomplete(自动补全)
2012-09-22 16:38 1466百度和google中都有 ... -
Compass将lucene、Spring、Hibernate三者结合
2012-09-01 10:29 1785Java代码 1.概述 Compass将 ... -
lucene3.0学习笔记之异常集锦(1)
2012-08-28 11:08 1123luceneJavaApachethread ... -
lucene3.0学习笔记(三)与paoding整合
2012-08-28 11:07 1215luceneApache.net 试过lucen ... -
lucene3.0学习笔记(二)index
2012-08-28 11:07 1012luceneApacheF# 1。IndexWr ... -
lucene3.0学习笔记(一)
2012-08-28 11:06 798luceneApacheCGIBlog工作 首先 ... -
struts2+spring+hibernate+compass 实现全文检索
2012-06-24 10:22 1615Compass是一流的开放源码JAVA搜索引擎框架,对于你的应 ... -
Compass2.2 学习笔记
2012-06-20 17:37 1294分类: 检索搜索 2012-01-10 20:49 36人阅 ... -
给你的网站加上站内搜索---Compass入门教程
2012-06-15 08:32 7211给你的网站加上站内搜索---Compass入门教程 ... -
COMPASS+spring 构建自己的搜索引擎
2012-06-12 13:06 1403在新架构中打算选择Compass或Hibernate Sear ...
相关推荐
在处理大量数据和需要高效搜索功能的项目中,Compass 可以提供比直接使用 Lucene 更高的抽象层次,使得开发者可以更专注于业务逻辑,而不是底层的搜索引擎技术细节。 总的来说,Compass 是一个强大的工具,它为 ...
### 基于Java的Luncene的Compass框架说明使用技术文档 #### 一、原理描述 Compass是一款优秀的开源Java搜索引擎框架,它能够帮助应用程序实现更为强大的搜索引擎语义能力。Compass依赖于顶级的Lucene搜索引擎,并...
Compass 支持对对象、持久化对象和 XML 文档的搜索,并具备事务管理功能。其设计灵感来源于 Hibernate,即 ORM 工具,Compass 与 Hibernate 类似,它在 Lucene 之上提供了一层抽象,简化了搜索引擎的集成。 三、...
【compass完整可用项目】是一个基于特定技术栈的软件开发项目,该项目的核心是Compass库,一个与Lucene紧密集成的全文搜索引擎工具。Compass提供了一种简单的方式来在Java应用程序中集成全文搜索功能,使得开发者...
这个压缩包包含了一个完整的Compass工程,MySQL的建库SQL脚本,以及相关的学习资料,非常适合想要深入理解并学习这两项技术的初学者。 Compass是一个基于Apache Lucene构建的开源全文搜索引擎,它为Java应用程序...
2. **Compass**: Compass被定义为面向领域模型的搜索框架,这意味着它必须支持对对象的搜索,包括持久化对象和XML文档对象的搜索,并且必须能够处理事务,包括创建、更新、保存和删除操作的事务级处理。因此,...
《深入探索Lucene+Compass技术与Ajax应用》 在当今的互联网开发中,数据检索和实时交互性已经成为不可或缺的功能。Lucene作为一个强大的全文搜索引擎库,为开发者提供了高效的文本搜索能力;Compass作为Lucene的一...
7. **性能优化**:Compass对Lucene进行了优化,例如通过内存映射文件和缓存技术提高检索速度,同时提供索引分片和复制策略,以适应大规模的数据和高并发环境。 8. **多语言支持**:Compass能够处理多种语言的文本,...
Compass 是基于 Lucene 构建的一个高级搜索引擎框架,它简化了 Lucene 的使用,并且提供了更多的特性,如自动索引、ORM 集成(Object-Relational Mapping)以及对多种持久化技术的支持,如 JPA、Hibernate 和 ...
**基于Lucene的搜索引擎框架Compass教程** 在信息爆炸的时代,如何快速、准确地检索到所需数据成为了一个关键问题。...理解并掌握Compass,有助于在实际项目中更好地利用全文搜索技术提升用户体验。
Compass的出现,使得非技术背景的用户也能直观地理解数据结构,简化了数据库的管理和操作流程。 在MongoDB Compass中,你可以进行以下主要操作: 1. 数据库浏览:通过Compass,用户可以清晰地看到数据库中的所有...
这个工具的主要目标是简化数据库的管理和操作,使非技术用户也能轻松理解和探索数据。"mongodb-compass-1.27.1-win32-x64.zip"是一个针对Windows 64位系统的MongoDB Compass版本的压缩包。 MongoDB Compass的核心...
通过这个压缩包,用户可以方便地下载、安装和使用MongoDB Compass,无需深入理解其背后的复杂技术细节。在实际工作中,MongoDB Compass可以帮助数据库管理员和开发人员更高效地管理和优化MongoDB数据库,提高工作...
### Compass与Lucene知识点详解 #### Lucene简介 **Lucene**是一款优秀的、成熟的、开源的、纯Java...通过这些测试可以帮助开发者更好地理解Compass在实际场景下的性能表现,从而做出更合理的架构决策和技术选型。
《compass:COMPASS 文档和用户手册》是针对 Compass 框架的详细参考资料,它为开发者和用户提供了深入理解及使用...同时,不断关注 Compass 的更新和社区动态,将帮助你保持技术的前沿性,应对不断变化的前端开发需求。
从官网下载的api,包括一些pfd文档和html形式文档,因csdn上传大小限制,特贴出下载网址:http://www.compass-project.org/,左边是下载链接,中间是手册,右边技术交流论坛
标题中的"S2SH+compass"指的是一个基于Struts2(S),Spring(S)和Hibernate(H)这三种开源框架的Java Web应用,再...如果想深入了解这些知识点,可以参考博文链接提供的内容,或者查阅相关框架和Compass的官方文档。
### Compass 2.1.0 参考文档知识点解析 #### 概览 ...Compass 提供了一个强大而灵活的搜索引擎解决方案,通过深入理解这些概念和技术细节,开发者可以更好地利用 Compass 来满足其应用程序的搜索需求。
5. **不同的映射技术**:Compass 支持多种映射策略,包括但不限于 OSEM、XSEM 和 RSEM,这些策略针对不同数据源的特点进行了优化。 #### 二、Compass:连接不同的数据源 **Compass** 作为核心框架,其主要目标之一...