Compass是建立在Lucene基础之上的一款开放源码的JAVA搜索引擎框架。它可以将common meta data与实体对象进行映射。最终通过访问common meta data来达到访问对象的目的。
三类配置文件
Compass的配置文件主要分成三类:
<compass-core-meta-data> <meta-data-group id="petclinic" displayName="Petclinic Meta Data"> <descrīption>Petclinic Meta Data</descrīption> <uri>http://compass/sample/petclinic</uri> <alias id="vet" displayName="Vet"> <descrīption>Vet alias</descrīption> <uri>http://compass/sample/petclinic/alias/vet</uri> <name>vet</name> </alias> ………… <meta-data id="petType" displayName="Pet Type"> <descrīption>The type of a pet</descrīption> <uri>http://compass/sample/petclinic/petType</uri> <name>petType</name> </meta-data> </meta-data-group> </compass-core-meta-data>
*.cmd.xml文件是对common meta data进行定义,我们就可以把它是当作Hibernate中的POJO来理解。里面定义了最终搜索的结果中的最基本的元数据。
<meta-data-group id="petclinic" displayName="Petclinic Meta Data"> 可当作是POJO的package来理解,petclinic可以看成是package name。
<alias id="vet" displayName="Vet"> 可当作是POJO的Class来理解,vet 可以看成是class name。
<meta-data id="petType" displayName="Pet Type">可当作是POJO的property来理解,petType可以看成是property name
<compass-core-mapping package="org.compass.sample.petclinic"> <contract alias="entity"> <id name="id" /> </contract> <contract alias="person" extends="entity"> <property name="firstName"> <meta-data>${petclinic.firstName}</meta-data> </property> <property name="lastName"> <meta-data>${petclinic.lastName}</meta-data> </property> <property name="address"> <meta-data>${petclinic.address}</meta-data> </property> <property name="city"> <meta-data>${petclinic.city}</meta-data> </property> <property name="telephone"> <meta-data>${petclinic.telephone}</meta-data> </property> </contract> <class name="Specialty" alias="${petclinic.specialty}" root="false"> <property name="name"> <meta-data>${petclinic.specialty}</meta-data> </property> </class> <class name="Owner" alias="${petclinic.owner}" extends="person"> <property name="firstName"> <meta-data>${petclinic.firstName}</meta-data> </property> <property name="lastName"> <meta-data>${petclinic.lastName}</meta-data> </property> <property name="address"> <meta-data>${petclinic.address}</meta-data> </property> <property name="city"> <meta-data>${petclinic.city}</meta-data> </property> <property name="telephone"> <meta-data>${petclinic.telephone}</meta-data> </property> <reference name="petsInternal" ref-alias="${petclinic.pet}" /> </class> </compass-core-mapping>
*.cpm.xml就是Object/Search Engine Mapping了。 我们也可以拿她当作同Hibernate中的*.hbm.xml来理解。他的作用就是提供了POJO到common meta data的映射package对应了POJO的包名,class对应了POJO类名,contract为POJO中一些较为Base类, property对应了POJO的属性。上面看到的像ANT中的${*}就是*.cmd.xml 中所定义的common meta data。通常来说*.cmd.xml中的alias同POJO的Class进行映射。Meta data 同Class中的property进行映射
<setting name="compass.engine.connection">target/index</setting> 指定了索引文件存放的路径。<compass-core-configuration> <compass> <setting name="compass.engine.connection">target/index</setting> <meta-data resource="org/compass/sample/library/library.cmd.xml" /> <mappings> <class name="test.Author" /> </mappings> </compass> </compass-core-configuration>
<meta-data resource="org/compass/sample/library/library.cmd.xml" /> 指定了*.cmd.xml文件存放的路径。
<mappings><class name="test.Author" /></mappings>是对compass的mapping文件进行指定。Test.Author对应的文件是test/Author.cpm.xml.