compass solr hibernate search 比较

http://www.iteye.com/topic/309214

 

想请各位大牛谈谈compass和solr的比较?  
不要说compass支持索引事务处理这么简单的东西。想了解一下compass和sorl掌握的难度,  
现在企业的应用的情况以及大家一般都是用什么东西来做搜索引擎的,compass or solr or lucnene?  

前些天时间自己用compass 搞了个搜索的东西,那个真不好用,例子非常少。。目前为止还有很多没搞定  

刚才看了下solr 文档那个感觉比compass详细多了,等下看看他的例子,compass的例子 跑不起来。  

如果用纯lucene的话,我怎么感觉比用这么些个框架还要好实现,最起码网上的资料非常多。  
虽然用纯lucene写起来代码比较繁琐,最起码遇到问题的时候还有个参考,可以找找,compass..? 没找到  

大家说说自己的意见看看。  
 
   发表时间:2009-01-03  
见意使用hibernate search
0    请登录后投票
 
   发表时间:2009-01-03  
见意使用hibernate search
0    请登录后投票
 
   发表时间:2009-01-03  
Hibernate的search 是采用lucene写的还是什么?
0    请登录后投票
 
   发表时间:2009-01-04  
Hibernate Search也是对Lucene的一个封装,我几年前使用Lucene做过一个项目,也不是很麻烦,Compass之类的框架也只是一个封装,至少你不用做很多重复性的劳动。
0    请登录后投票
 
   发表时间:2009-01-04  
恩,那到时,纯lucene 确实比较繁琐,而compass封装好了,不过它的API可能由于是能力有限,所以不大会用  
solr 呢?谁用过,说说意见啊

我喜欢lucene技术,也不知道是为什么喜欢 ?所以想来问问
0    请登录后投票
 
   发表时间:2009-01-14  
solr 可以比较快速的建立一个应用. 因为 lucene 的文档结构是可配置的.  

compass 不太了解, 它也可以配置吧
0    请登录后投票
 
   发表时间:2009-01-14   最后修改:2009-01-14
建议使用solr,其中的分组统计功能特别好使,例子也多,只是稍稍部署有点烦。Compass与Hibernate Search个人感觉差不多,两者与Hibernate集成都不用写什么代码,Compass还支持好几种持久框架集成,Hibernate Search好像只支持Hibernate。想diy,就直接用Lucene。
0    请登录后投票
 
   发表时间:2009-02-02  
如果是使用ssh框架建议用compass,compass封装的比较好,只是有个问题就是中文资料比较少,而且 不全。。
0    请登录后投票
 
   发表时间:2009-02-13  
其实compass只是简单的应用的话,也很容易上手的  
假如使用了hibernate+spring+compass  
关于compass在spring中的配置如下,保存为一个xml文件,在web.xml中引入即可  
Java代码    收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">  
  3. <beans>  
  4.     <bean id="annotationConfiguration" class="org.compass.annotations.config.CompassAnnotationsConfiguration"></bean>  
  5.   
  6.     <bean id="compass" class="org.compass.spring.LocalCompassBean">  
  7.         <!-- 这里的配置意思是指需要搜索的POJO对象 -->  
  8.         <property name="classMappings">  
  9.             <list>  
  10.                 <value>com.tourye.model.TnInfomation</value>  
  11.             </list>  
  12.         </property>  
  13.                 <!-- 这里的配置意思是指使用annotation进行compass配置 -->  
  14.         <property name="compassConfiguration" ref="annotationConfiguration" />  
  15.         <property name="compassSettings">  
  16.             <props>  
  17.                 <prop key="compass.engine.connection">/home/dev/compass</prop>这里说明索引文件所放的目录  
  18.                 <prop key="compass.transaction.factory">org.compass.spring.transaction.SpringSyncTransactionFactory</prop>  
  19.                 <!-- <prop key="compass.engine.analyzer.default.type">net.paoding.analysis.analyzer.PaodingAnalyzer</prop> -->这里的注释是为了说明使用paoding的分词器,由于测试时,有时会出问题,所以暂时禁用  
  20.             </props>  
  21.         </property>  
  22.         <property name="transactionManager">  
  23.             <ref bean="transactionManager" />  
  24.         </property>  
  25.         <!--  
  26.             高亮设置,未测试成功,需要相关的代码辅助 <property name="compass.engine.highlighter.default.formatter.simple.pre"> <value><![CDATA[<font  
  27.             color="red"><b>]]></value> </property> <property name="compass.engine.highlighter.default.formatter.simple.post">  
  28.             <value><![CDATA[</b></font>]]></value> </property>  
  29.         -->  
  30.     </bean>  
  31.         下面的两段配置是为了说明compass构建索引与hibernate的insert/delete/update操作同步  
  32.     <bean id="hibernateGpsDevice" class="org.compass.gps.device.hibernate.HibernateGpsDevice">  
  33.         <property name="name">  
  34.             <value>hibernateDevice</value>  
  35.         </property>  
  36.         <property name="sessionFactory">  
  37.             <ref bean="mySessionFactory" />  
  38.         </property>  
  39.         <property name="nativeExtractor">  
  40.             <bean class="org.compass.spring.device.hibernate.SpringNativeHibernateExtractor" />  
  41.         </property>  
  42.     </bean>  
  43.   
  44.     <bean id="compassGps" class="org.compass.gps.impl.SingleCompassGps" init-method="start" destroy-method="stop">  
  45.         <property name="compass">  
  46.             <ref bean="compass" />  
  47.         </property>  
  48.         <property name="gpsDevices">  
  49.             <list>  
  50.                 <bean class="org.compass.spring.device.SpringSyncTransactionGpsDeviceWrapper">  
  51.                     <property name="gpsDevice" ref="hibernateGpsDevice" />  
  52.                 </bean>  
  53.             </list>  
  54.         </property>  
  55.     </bean>  
  56.   
  57.     <!-- 自动随Spring ApplicationContext启动而重建索引,未研究 -->  
  58.     <bean id="compassIndexBuilder" class="com.tourye.service.timer.CompassIndexBuilder" lazy-init="false">  
  59.         <property name="compassGps" ref="compassGps" />  
  60.         <property name="buildIndex" value="true" />  
  61.         <property name="lazyTime" value="10" />  
  62.     </bean>  
  63. </beans>  


第二步:  
使用annotatio声明要索引的object,如下所示,自己根据需要进行设置  
相关文档 参考: http://www.compass-project.org/docs/2.2.0M2/reference/html/core-osem.html#core-osem-searchableclasses  
Java代码    收藏代码
  1. @Searchable  
  2. public class TnInfomation implements java.io.Serializable {  
  3.     /** 
  4.      *  
  5.      */  
  6.     private static final long serialVersionUID = -4503017770118428686L;  
  7.       
  8.     @SearchableId(name = "id")  
  9.     private Long              id;  
  10.       
  11.     private int               type;  
  12.     @SearchableProperty(name="title")  
  13.     private String            title;  
  14.     @SearchableProperty(name="keywords")  
  15.     private String            keywords;  
  16.     @SearchableProperty(name="content")  
  17.     private String            content;  
  18.     private int               author;  
  19.     private Date              createtime;  
  20.     private Date              updatetime;  
  21.     @SearchableProperty(name="approvetime")  
  22.     private Date              approvetime;  
  23.     private int               clicks;  
  24.     private int               critiques;  
  25.     private String            provenance;  
  26.     @SearchableProperty(name="status")  
  27.     private byte              status; /* 待审核(0) 已审核(1)*/  


第三步,建立搜索service  
Java代码    收藏代码
  1. public class InfomationSearchServiceImpl implements InfomationSearchService {  
  2.     private Compass compass;  
  3.   
  4.     public Compass getCompass() {  
  5.         return compass;  
  6.     }  
  7.   
  8.     public void setCompass(Compass compass) {  
  9.         this.compass = compass;  
  10.     }  
  11.   
  12.     /* 
  13.      * (non-Javadoc) 
  14.      *  
  15.      * @see 
  16.      * com.tourye.infomation.compass.InfomationSearchService#search(java.lang 
  17.      * .String, int, int) 
  18.      */  
  19.     public CompassSearchResults search(String query, int page, int pageSize) throws Exception {  
  20.         CompassSession session = compass.openSession();  
  21.         try {  
  22.             session.beginTransaction();  
  23.             //构建compass查询编辑器  
  24.             CompassQueryBuilder querybuilder = session.queryBuilder();  
  25.             CompassQuery cq = null;  
  26.             CompassSearchCommand csc = null;  
  27.             //声明查询条件,query是查询字符串  
  28.             if (StringUtils.isNotEmpty(query)) {  
  29.                 cq = querybuilder.bool().addMust(querybuilder.spanEq("status"1)).addMust(  
  30.                         querybuilder.queryString(query).toQuery()).toQuery();  
  31.                 cq.addSort("approvetime", CompassQuery.SortDirection.REVERSE);  
  32.                 csc = new CompassSearchCommand(cq, new Integer(Math.max(0, page - 1)));  
  33.             } else {  
  34.                 csc = new CompassSearchCommand(query.trim());  
  35.             }  
  36.             // 搜索命令InfomationSearchHelper和CompassSearchHelper相同,自己可以实现  
  37.             InfomationSearchHelper searchHelper = new InfomationSearchHelper(compass, pageSize);  
  38.             CompassSearchResults searchResults = searchHelper.search(csc);  
  39.   
  40.             return searchResults;  
  41.         } finally {  
  42.             if (session != null) session.close();  
  43.         }  
  44.     }  
  45. }  


这样就可以了
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值