hibernate search - FieldBridge 样例

由于业务的复杂度和需要求各不想同,在建立索引时,hibernate search默人会解析一些基本的类型,但基提供了FieldBridge来进行处理,下边是一个例子
@Entity
@Indexed(index = "Announcement")
public class Announcement implements java.io.Serializable {

@Field(name = "announcementRecordDate", store = Store.YES)
@FieldBridge(impl = TimestampFieldBridge.class)
private Timestamp announcementRecordDate;

}


public class TimestampFieldBridge implements StringBridge {

@Override
public String objectToString(Object value) {
  if (value == null)
   return null;
  if (value instanceof Timestamp) {
   return com.snow.util.DateUtil.getTimestamp((Timestamp) value);
  } else {
   throw new IllegalArgumentException("index error " + value.getClass().toString());
  }
}
}


这个只是一个示例,其实hibernate search提供了很多的类型,让我们来进行处理。

[a href='http://yanlong137.iteye.com/category/135435'][/a]

你可能感兴趣的:(Hibernate)