Let's say I have a domain object that looks like this:
@Entity
@Indexed
public class Thingie implements DomainObject {
private Long id;
private Integer version;
private String title;
private List<String> keywords = new Vector<String>();
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Version
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
@Column(length=64, nullable=false)
@Field(index=Index.TOKENIZED,store=Store.NO)
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@ElementCollection
// what do I put here??
public List<String> getKeywords() {
return keywords;
}
public void setKeywords(List<String> keywords) {
this.keywords = keywords;
}
}
How do I annotate the keywords field such that I can do a search like this that will do a full text search of the title and keywords:
org.apache.lucene.search.Query query = qb.keyword().onFields("title","keywords")
.matching("search").createQuery();
you can use StringBridge. check 4.2.2.1. StringBridge in
http://docs.jboss.org/hibernate/search/3.1/reference/en/html/search-mapping-bridge.html
For example, if you store keywords in database in format of: aa,bb,cc
one implementation could be: