首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

compass跟spring 集成实现实时搜索

2012-11-13 
compass和spring 集成实现实时搜索1.增加compass2.20的jar包 2.用annotation在pojo类里面增加实现搜索的功

compass和spring 集成实现实时搜索
1.增加compass2.20的jar包
2.用annotation在pojo类里面增加实现搜索的功能

Person类    import org.compass.annotations.Index;    import org.compass.annotations.Searchable;    import org.compass.annotations.SearchableId;    import org.compass.annotations.SearchableProperty;    import org.compass.annotations.Store;          @Searchable   public class Person {        @SearchableId       private int id;        //@SearchableProperty(name="name") --- 这个默认的是分词,存储        @SearchableProperty(name="name")        private String name;        //不分词,用下面的annotation定义        @SearchableProperty(index = Index.UN_TOKENIZED, store = Store.YES)        private String sex;        @SearchableProperty(name="adress")        private String address;        @SearchableProperty(index = Index.UN_TOKENIZED, store = Store.YES)        private String duty;        @SearchableProperty(index = Index.UN_TOKENIZED, store = Store.YES)        private String phone;        @SearchableProperty(name="description")        private String description;           public int getId() {            return id;         }           public void setId(int id) {            this.id = id;         }           public String getName() {            return name;         }           public void setName(String name) {            this.name = name;         }           public String getSex() {            return sex;         }           public void setSex(String sex) {            this.sex = sex;         }           public String getAddress() {            return address;         }           public void setAddress(String address) {            this.address = address;         }           public String getDuty() {            return duty;         }           public void setDuty(String duty) {            this.duty = duty;         }           public String getPhone() {            return phone;         }           public void setPhone(String phone) {            this.phone = phone;         }           public String getDescription() {            return description;         }           public void setDescription(String description) {            this.description = description;         }       }   


3.增加一个applicationContext-compass.xml文件,配置compass

<?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"           ref="annotationConfiguration" />                         <property name="transactionManager" ref="transactionManager" />                         <property name="compassSettings">                 <props>                     <!-- 指定索引的路径 -->                     <prop key="compass.engine.connection">e:/compass</prop>                     <!-- 指定分词器 -->                     <prop key="compass.engine.analyzer.default.type">net.paoding.analysis.analyzer.PaodingAnalyzer</prop>                     <prop key="compass.transaction.factory">                         org.compass.spring.transaction.SpringSyncTransactionFactory                     </prop>                                       </props>             </property>                     </bean>               <bean id="hibernateGpsDevice"           ref="sessionFactory" />             <property name="mirrorDataChanges">                 <value>true</value>             </property>         </bean>         <!-- 同步更新索引 通过compassGps-->         <bean id="compassGps"            init-method="start" destroy-method="stop">             <property name="compass" ref="compass" />             <property name="gpsDevices">                 <list>                     <bean                        ref="hibernateGpsDevice" />                     </bean>                 </list>             </property>         </bean>               <bean id="compassTemplate"           ref="compass" />         </bean>            <!-- 定时重建索引(利用quartz)或随Spring ApplicationContext启动而重建索引 -->         <bean id="compassIndexBuilder"                      lazy-init="false">             <property name="compassGps" ref="compassGps" />             <property name="buildIndex" value="true" />             <property name="lazyTime" value="10" />         </bean>               </beans>   

热点排行