`
dragonzhu
  • 浏览: 14270 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论
阅读更多
这是我第一篇成文的英文技术翻译,里面一些常用的技术名词没有翻译,英文单词意思更明了

Compass提供了一些简单和熟悉的API。说熟悉是因为他为了降低学习曲线模拟了当前流行的ORM工具 API,Compass API围绕了几个主要接口:
CompassConfiguration:用于配置compass一系列的设置,配置文件和映射定义。接着创建一个Compass实例
Compass:一个线程安全的实例,为单线程的使用打开Compass Sessions。同时也提供了一些搜索引擎索引级别的操作。
CompassSesssion:实行搜索引擎操作(save, delete, find, and load)的主要接口。非常轻量级的和非线程安全的
CompassTransaction:控制compass事务的一个接口。用于不要求事务控制环境(像Spring/JTA)
下面是使用API的一个例子:
// Compass is configured and created on an application scope
 CompassConfiguration conf =  new CompassConfiguration().setConnection("/tmp/index").addClass(Author.class);
 Compass compass = conf.buildCompass();

  // A request scope operation
 CompassSession session = compass.openSession();
 CompassTransaction tx = null;
 try {
     tx = session.beginTransaction();
     ...
     session.save(author);
     Compass hits = session.find("jack london");
     Author a = (Author) hits.data(0);
     Resource r = hits.resource(0);
     ...
     tx.commit();
 } catch (CompassException ce) {
     if (tx != null) tx.rollback();
 } finally {
     session.close();
 }
为了简化事务管理代码,compass提供了许多选择。首先去用使用了流行模板设计模型的CompassTemplate,其次当处于事务管理环境中,compass和事务管理者(JTA和hibernate事务)集成,随着已经运行的食物而运行。在一个Session操作实行时,CompassSession作为一个代理自动参与事务。代理是通过编程或使用Spring Ioc创建。
Compass支持自动事务操作,集成了不同的事务管理策略:Local transaction management, JTA Sync and XA for JTA integration, and Spring Synchronization integration.Compass configuration是基于key value设置的,Compass配置可以使用编程配置,基于xml DTD配置(定义mappings and settings)和一个基于xml schema 配置。基于xml schema 配置可以得到基于Spring 2 新的schema配置支持。
搜索引擎映射
Compass的主要特征之一就是有从应用程序模型到搜索引擎映射的能力。搜索引擎域模型是由Resource (a Lucene Document) 和Property (a Lucene Field)组成的。他是用于索引可以搜索内容的抽象数据对象。
RSEM
第一映射是RSEM(Resource/SearchEngine Mapping). 这是一个低级别的映射,从Compass Resource 和 Property(对应 Lucene Document and Field) 搜索引擎抽象到搜索引擎。下面是一个关于Author resource 的RESM描述的例子:<resource alias="author">  </resource>
<resource alias="author"><resource-id name="id"><resource-property name="firstName"><resource-property index="tokenized" store="yes" name="lastName"><resource-property name="birthdate" converter="mydate"></resource-property><resource alias="author">
<resource-id name="id"/>
<resource-property name="firstName"/>
<resource-property name="lastName" store="yes" index="tokenized"/>
<resource-property name="birthdate" converter="mydate"/>
</resource>
</resource-property></resource-property></resource-id></resource>
<resource alias="author"><resource-id name="id"><resource-property name="firstName"><resource-property name="lastName" store="yes" index="tokenized"> 这里我们描述一个资源映射author别名。资源映射有一个Id关联资源和几个额外的属性。定义属性是可选的,他们可以控制不同属性特征,包含了和converter联合的能力。下面是一段用数据填充的author资源和索引此资源的代码。
Resource r = session.createResource("author");
  r.addProperty("id", "1")
    .addProperty("firstName", "jack")
    .addProperty("lastName", "london")
    .addProperty("birthdate", new Date());
  session.save(r);
许多compass特征在上面的代码片段中展示。第一个特征要感谢这个实施:如果资源已经存在索引中,一个标识的Compass可以更新它。第二个特征是能显式分配converter给property,能使用许多Compass内置的converter。下面是Compass configuration(包含“mydate” converter 配置)
<compass-core-config xmlns="http://www.opensymphony.com/compass/schema/core-config"><compass-core-config xmlns="http://www.opensymphony.com/compass/schema/core-config"
      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="index" />
    </connection>
      <converters>
        <converter name="mydate" type="org.compass.core.converter.basic.DateConverter">
          <setting name="format" value="yyyy-MM-dd" />
        </converter>
      </converters>
      <mappings>
        <resource location="sample/author.cpm.xml" />
      </mappings>
    </compass>
  </compass-core-config></compass-core-config></resource-property></resource-property></resource-id></resource><compass-core-config xmlns="http://www.opensymphony.com/compass/schema/core-config"><compass name="default">
<connection><converters></connection></compass></compass-core-config> <resource alias="author"><resource-id name="id"><resource-property name="firstName"><resource-property name="lastName" store="yes" index="tokenized"><compass-core-config xmlns="http://www.opensymphony.com/compass/schema/core-config"><compass name="default"><connection>没有翻译完整,后面还有OSEM (Object/Search Engine Mapping),XSEM (Xml/Search Engine Mapping)

</connection></compass></compass-core-config></resource-property></resource-property></resource-id></resource>

Compass Gps

分享到:
评论
1 楼 yangyang1484 2007-08-19  
希望楼主继续翻译剩下的章节辛苦。

相关推荐

Global site tag (gtag.js) - Google Analytics