欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
Compass讀文檔筆記

    Compass是基于Lucene的更高層的抽象,假如你正打算做關(guān)于搜索方面的模塊的話(huà),那我建議你使用Compass,他提供了可配置方案,而且比Lucene更加容易使用。如果你的系統中使用Spring, Hibernate,JDO, IBatis。。。 Compass是最好的選擇,他能夠非常方便的集成到現有系統中去。
1.   Compass的framework的系統結構。
感覺(jué)Compass的代碼的結構簡(jiǎn)直就是剽竊Hibernate的,可能Compass的最初目的是用來(lái)整合Hibernate的,

CompassConfiguration conf =
    new CompassConfiguration().configure().addClass(Author.class);
Compass compass = conf.buildCompass();
CompassSession session = compass.openSession();
CompassTransaction tx = null;
try {
    tx = session.beginTransaction();
    ...
    session.save(author);
    CompassHits hits = session.find("jack london");
    Author a = (Author) hits.data(0);
    Resource r = hits.getResource(0);
    ...
    tx.commit();
} catch (CompassException ce) {
    if (tx != null) tx.rollback();
} finally {
    session.close();
}

假如你對Hibernate有了解的話(huà),相信你對Compass會(huì )比較容易理解的,你可以把Hibernate的思想轉移到Compass上?,F在讓我們看看他們之間的相似吧。
compass.cfg.xml

<compass-core-config xmlns="http://www.opensymphony.com/compass/schema/core-config"

  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.opensymphony.com/compass/schema/core-config
           http://www.opensymphony.com/compass/schema/compass-core-config.xsd">

   <compass name="default">
      <connection>
          <file path="target/test-index"/>
      </connection>
  
      <mappings>
          <class name="test.Author" />
      </mappings>
  
   </compass>
</compass-core-config>  
這個(gè)是Compass總的配置文件,其中定義了索引文件存儲的位置(這里是用文件系統,Compass有多種選擇,你也可以選數據庫或其他),Compass索引的對象是面向PoJo的,這里的是Author,對應的文件是test/Author.cpm.xml.
當然這里面的配置屬性不止這么多,更多的屬性見(jiàn)Configure屬性。

CompassConfiguration conf = new CompassConfiguration()
     .setSetting(CompassEnvironment.CONNECTION, "my/index/dir")
     .addResource(DublinCore.cmd.xml).addClass(Author.class);
Compass compass = conf.buildCompass();
這里我們CompassConfiguration會(huì )讀取默認的在classpath中的compass.cfg.xml初始化,然后得到Compass對象,可能你會(huì )馬上意思到這個(gè)Compass肯定對應于Hibenate中的SessionFactory,是的,這是一個(gè)重量級的對象,
我們需要通過(guò)這個(gè)對象得到CompassSession,然后進(jìn)行CRUD操作,CompassSession跟Hibernate中的Session一樣是個(gè)lightweight對象。關(guān)于對Search domain的配置(Author.cpm.xml),大家可以查看cpm文件配置。在那里面
主要是定義了那些properties是需要被索引的。

<?xml version="1.0"?>


<compass-core-mapping package="eg">

  <class name="Author" alias="author">

    <id name="id" />

    <constant>
      <meta-data>type</meta-data>
      <meta-data-value>person</meta-data-value>
      <meta-data-value>author</meta-data-value>
    </constant>

    <property name="name">
      <meta-data>name</meta-data>
      <meta-data>authorName</meta-data>
    </property>

    <property name="birthday">
      <meta-data>birthday</meta-data>
    </property>

    <component name="books" ref-alias="book" />

    <!-- can be a reference instead of component
    <reference name="books" ref-alias="book" />
    -->

  </class>

  <class name="Book" alias="book">

    ...

  </class>

</compass-core-mapping>

2.  索引文件結構
---[index dir]/index
  |
  |-- [subIndex1]
  |      |
  |      |--- segments
  |      |--- [segment1]
  |      |--- [segment2]
  |
  |-- [subIndex2]
  |      |
  |      |--- segments
  |      |--- [segment1]
  |      |--- [segment2]
  |      |--- [segment3]
  |
...
基本上是一個(gè)search domain放到一個(gè)subIndex文件夾中,更確切的說(shuō)是相同alias name的search domain放到相同的sub index folder中。

3.  Compass中的操作
通過(guò)CompassSession我們可以進(jìn)行save,delete, get,load。假如我們有兩個(gè)domain Object,Author和 Book,假如我們想要query Book的話(huà)要怎樣做呢? 我們需要使用alias(這個(gè)屬性定義在cmp文件中),
通過(guò)CompassQueryBuilder去構造CompassQuery, CompassQueryBuilder非常靈活,非常像Hibernate的Criteria查詢(xún)。具體的sample請看 Working with objects  

CompassHits hits = session.createQueryBuilder()
  .queryString("+name:jack +familyName:london")
    .setAnalyzer("an1") // use a different analyzer
  .toQuery()
    .addSort("familyName", CompassQuery.SortPropertyType.STRING)
    .addSort("birthdate", CompassQuery.SortPropertyType.INT)
  .hits();

4.  CompassGps and CompassGpsDevice
CompassGps像是一個(gè)Service,他需要在application startup時(shí)啟動(dòng)服務(wù), applicationshutdown停止服務(wù),CompassGpsDevice不能獨立的存在,他需要依賴(lài)CompassGps,CompassGps為CompassGpsDevice提供
Compass對象,他們一起為程序提供Index的實(shí)時(shí)更新。Compass整合Hibernate 等等 persitanceframework的代碼就在CompassGpsDevice里,你需要提供不同的Device,如HibernateDevice,JDODevice。你也
可以實(shí)現自己的Device, CompassGpsDevice會(huì )把domain object的更新事件通過(guò)CompassGps去通知Compass去更新索引文件,這樣就是可以實(shí)時(shí)更新index了。有興趣的話(huà)可以看看Hibernate3GpsDevice的
registerEventsForHibernate31()方法,他給Hibernate的save,delete,update操作增加listener。當然我們可以使用aop自己去實(shí)現這塊。CompassGps and CompassGpsDevice  

Compass compass = ... // configure compass
CompassGps gps = new SingleCompassGps(compass);
CompassGpsDevice device1 = ... // configure the first device
device1.setName("device1");
gps.addDevice(device1);
CompassGpsDevice device2 = ... // configure the second device
device2.setName("device2");
gps.addDevice(device2);

gps.start();
....
....
//on application shutdown
gps.stop();

5.  整合Spring,Hibenate
在Compass的lib里面就有非常好的一個(gè)sample了(petclinic),里面有對Spring,Hibenate的整合,其實(shí)對spring來(lái)說(shuō)也就是通過(guò)ioc把CompassGps 和 Compass定義好。CompassGps主要負責re-index和index實(shí)時(shí)更新
,Compass主要提供了自定義Search部分的入口(CompassTemplate)。Spring提供了對Compass的DAO的整合,在CompassDaoSupport 中拿到CompassTemplate,這個(gè)跟spring對hibernatedao的支持是一致的。

public class LibraryCompassDao extends CompassDaoSupport {
    public int getNumberOfHits(final String query) {
       Integer numberOfHits = (Integer)getCompassTemplate().execute(
           new CompassCallback() {
               public Object doInCompass(CompassSession session) {
                  CompassHits hits = session.find(query);
                  return new Integer(hits.getLength());
               }
           }
       );
    }
    return numberOfHits.intValue();
}
<beans>
   <bean id="libraryCompass" class="LibraryCompassDao">
      <property name="compass">
         <ref local="compass" />
      </property>
   </bean>
</beans>
         <!-- COMPASS START -->
    <bean id="compass" class="org.compass.spring.LocalCompassBean">
        <property name="resourceLocations">
            <list>
                <value>classpath:org/compass/sample/petclinic/petclinic.cmd.xml</value>
                <value>classpath:petclinic.cpm.xml</value>
            </list>
        </property>
        <property name="compassSettings">
            <props>
                <prop key="compass.engine.connection">file://${user.home}/compass/petclinic</prop>
                <propkey="compass.transaction.factory">org.compass.spring.transaction.SpringSyncTransactionFactory</prop>
            </props>
        </property>
        <property name="transactionManager">
            <ref local="transactionManager" />
        </property>
    </bean>
         <bean id="hibernateGpsDevice" class="org.compass.spring.device.hibernate.SpringHibernate3GpsDevice">
           <property name="name"><value>hibernateDevice</value></property>
           <property name="sessionFactory"><ref local="sessionFactory" /></property>
         </bean>
         <bean id="compassGps" class="org.compass.gps.impl.SingleCompassGps" init-method="start" destroy-method="stop">
           <property name="compass"><ref bean="compass" /></property>
           <property name="gpsDevices">
             <list>
               <ref local="hibernateGpsDevice" />
             </list>
           </property>
         </bean>
         <!-- COMPASS END -->
        <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
        <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
                <property name="sessionFactory"><ref local="sessionFactory"/></property>
        </bean>


<!----------------------------一下是對anototion的配置。-->
    <bean id="annotationConfiguration"
          class="org.compass.annotations.config.CompassAnnotationsConfiguration">
    </bean>

    <!-- 核心Compass Bean,search及index時(shí)使用 -->
    <bean id="compass" class="org.compass.spring.LocalCompassBean">
        <!-- anontaition式設置         -->
        <property name="classMappings">
            <list>
                <value>com.dengyin.compass.sample.domain.Book</value>
            </list>
        </property>

        <property name="compassConfiguration" ref="annotationConfiguration"/>

        <!-- xml 文件式設置
                        <property name="resourceLocations">
                        <list>
                        <value>classpath:compass-springside.cmd.xml</value>
                        <value>classpath:compass-springside.cpm.xml</value>
                        </list>
                        </property>
                -->
        <property name="compassSettings">
            <props>
                <prop key="compass.engine.connection">
                    file://${user.home}/springside/compass
                </prop>
                <prop key="compass.transaction.factory">
                    org.compass.spring.transaction.SpringSyncTransactionFactory
                </prop>
            </props>
        </property>

        <property name="transactionManager" ref="transactionManager"/>
    </bean>

    <!--Compass的GPS綁定,在index時(shí)使用-->
    <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.hibernate.SpringHibernate3GpsDevice">
                    <property name="name">
                        <value>hibernateDevice</value>
                    </property>
                    <property name="sessionFactory" ref="sessionFactory"/>
                </bean>
            </list>
        </property>
    </bean>

ok! 相信你對Compass有一定的了解了。 thanks

Compass:    http://www.opensymphony.com/compass/
Compass文檔:http://www.opensymphony.com/compass/content/documentation.html
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
Compass入門(mén)及其與Spring、iBatis的整合
利用Compass實(shí)現一個(gè)簡(jiǎn)單的搜索引擎[轉貼]
用compass實(shí)現站內全文搜索引擎(二) - Miss - JavaEye技術(shù)網(wǎng)站
Spring多數據源的配置和使用
Java程序中連接池、及參數綁定實(shí)現
spring下hibernate事務(wù)配置范例
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久