lucence and annotation

Compass: Integrate Search into your apps有时间翻译一下这篇文章

昨天晚上看了一下 luncence in action,今天又找了一个例子
1 Query query = QueryParser.parse(searchWords, "title", language);
2 query = new WildcardQuery(new Term("title",searchWords[i]));
3 query = new FuzzyQuery(new Term("title",searchWords[i]));
4 Term begin = new Term("birthDay","20000101");
Term end   = new Term("birthDay","20060606");
 Query query = new RangeQuery(begin,end,true);

springside中用了compass(专门用于数据库索引),好好研究研究

annotation 也是比较新的东西,有hibernate annotation,...下面是 springside中用的例子
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Undeletable {
String status() default "status";
}

   原本怪Sun怎么这么抠门,用@interface 而不另外搞一个关键字,原来Sun的意思就是把Interface和Annotation的定位一样呀。
   @Target 定义Annotation 可用在什么地方,比如类型,函数,函数参数等。Type代表Class,Interface...
   @Retention(RetentionPolicy.RUNTIME)表明是个运行期的annotation,否则后面的代码就不会起作用了。
   String status() 定义了annotation有个status的属性,而且可以定义默认值为 "status"。
   Annotation在Entity使用:

@Undeletable

  public class Book{
private String status;
public void setStatus(String status) {
this.status = status;
}
}

@Undeletable(status = "status2")
public class BookWithNewStatus {
private String status2;
public void setStatus2(String status2) {
this.status2 = status2;
}
}

在框架中的判断:

if (entityClass.isAnnotationPresent(Undeletable.class)) {
Undeletable anno = (Undeletable) entityClass.getAnnotation(Undeletable.class);
statusProperty = anno.status();
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值