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();
}





你可能感兴趣的:(Hibernate,框架,sun)