不做浮躁的人
正在行走的人...
posts - 171,  comments - 51,  trackbacks - 0
通用元数据提供了将元数据名称和别名定义从osem文件提取到外面的方式。当你的应用程序有大量的域模型时尤其有用。另外一个优势就是添加额外的信息倒元数据中,不如描述。也能制定元数据定义的格式,这样就不用在osem 文件中定义了 。
通过集中话元数据,其它工具也能更好地利用这些信息。
OSEM文件引用通用元数据的方式是采用${}.

query syntax:
jack :缺省的查询域中包括jack字段。
jack london:缺省的查询域中包括 jack 或 london, 或者2者都有。
+jack +london: 缺省的查询域中必须包括jack和london。
name:jack:name字段中包括jack。
name:jack -city:london :name字段中包括jack但是city字段中不包括london。
name:"jack london" :name字段中包括jack london短语。
name:"jack london"~5 :name字段包括至少5次jack and london短语
jack* 包含以jack开头的词条。
jack~ 包括以jack结尾的词条。
birthday:[1870/01/01 TO 1920/01/01] birthday从1870-01-01到1920-01-01。


CompassHits, CompassDetachedHits & CompassHitsOperations:
compassHits:所有的搜索结果都是通过该接口访问。只能用在事务上下文中。如果脱离上下文,则需要detached。compassHits和compassDetachedHits都共享相同的操作接口:compassHitsOperation。

getLength() or length() :得到搜索资源的长度
score(n) 第n个搜索资源的分值。
resource(n) 第n个搜索资源
data(n) 第n个对象实例。

CompassQuery and CompassQueryBuilder:
CompassQueryBuilder提供了程序创建compassQuery的功能。compassQuery能够用来添加排序和执行查询。
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();

CompassQueryBuilder queryBuilder = session.createQueryBuilder();
CompassHits hits = queryBuilder.bool()
.addMust( queryBuilder.term("name", "jack") )
.addMustNot( queryBuilder.term("familyName", "london") )
.toQuery()
.addSort("familyName", CompassQuery.SortPropertyType.STRING)
.addSort("birthdate", CompassQuery.SortPropertyType.INT)
.hits();

注意排序的属性必须是un_tokenized。

OSEM映射文件:
<class name="eg.A" alias="a">
<id name="id" />
<property name="familyName">
<meta-data>family-name</meta-data>
</property>
<property name="date">
<meta-data converter-param="YYYYMMDD">date-sem</meta-data>
</property>
Working with objects
Compass - Java Search Engine 78
</class>
查询方式:采用compassQueryBuilder,许多查询可以直接工作在mapping的层次上。
CompassQueryBuilder queryBuilder = session.createQueryBuilder();
CompassHits hits = queryBuilder.term("a.familyName.family-name", "london").hits();
// 采用类属性的元数据id, 在上面的例子中将采用第一个元数据.
CompassHits hits = queryBuilder.term("a.familyName", "london").hits();
//查询编辑器将会采用相应的转化器转换数据。
CompassHits hits = queryBuilder.term("a.date.date-sem", new Date()).hits();
CompassHits hits = queryBuilder.bool()
.addMust( queryBuilder.alias("a") )
.addMust( queryBuilder.term("a.familyName", "london") )
.toQuery().hits();

CompassHighlighter:提供高亮度匹配搜索的文字字段。
CompassHits hits = session.find("london");
String fragment = hits.highlighter(0).fragment("description");
高亮度只能用于CompassHits,只能用在事务上下文中。

在detachedHits中使用高亮度:
CompassHits hits = session.find("london");
//在事务上下文中处理高亮度。
for (int i = 0.; i < 10; i++) {
hits.highlighter(i).fragment("description"); // this will cache the highlighted fragment
}
CompassHit[] detachedHits = hits.detach(0, 10).getHits();
// outside of a transaction (maybe in a view technology)
for (int i = 0; i < detachedHits.length; i++) {
// this will return the first fragment
detachedHits[i].getHighlightedText().getHighlightedText();
// this will return the description fragment, note that the implementation
// implements the Map interface, which allows it to be used simply in JSTL env and others
detachedHits[i].getHighlightedText().getHighlightedText("description");
}
posted on 2006-12-02 14:54 不做浮躁的人 阅读(3313) 评论(1)  编辑  收藏

FeedBack:
# re: compass学习笔记3
2007-09-13 03:52 | jlive@live.com
请问 compass支持cascade吗

如果我根据A的某个字段检索出了A,B会同时被检索出来吗

我在一个应用里做的时候显示B是 null


  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航:
 

<2006年12月>
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

常用链接

留言簿(9)

随笔分类(31)

随笔档案(75)

文章分类(1)

文章档案(3)

搜索

  •  

最新评论

阅读排行榜

评论排行榜