Hi,
I indexed a JPA-entity via a Class-Bridge annotation, and so far everything is fine (BTW I'm using Hibernate Search 3.3.0 Final).
But when I want to search for a indexed property, I get the following error:
Code:
org.hibernate.search.SearchException: Unable to find field detail.BE_en in it.hsearch.test.CollectDetail
at org.hibernate.search.engine.DocumentBuilderIndexedEntity.objectToString(DocumentBuilderIndexedEntity.java:607)
at org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsTermQueryBuilder.buildSearchTerm(ConnectedMultiFieldsTermQueryBuilder.java:133)
at org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsTermQueryBuilder.createQuery(ConnectedMultiFieldsTermQueryBuilder.java:92)
at org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsTermQueryBuilder.createQuery(ConnectedMultiFieldsTermQueryBuilder.java:73)
It seems that Hibernate Search cannot find or doesn't know of the field detail.BE_en although via Luke I can see it in the index.
Here's my entity:
Code:
@Entity
@Table( name = "COLLECT_DETAIL" )
@Indexed
@ClassBridge(name="detail",
index=Index.TOKENIZED,
store=Store.YES,
impl = CollectDetailBridge.class)
public class CollectDetail {
private Long pk;
private String tag;
private String lang;
private Long occ;
private String content;
@Id
public Long getPk() {
return pk;
}
public void setPk(Long pk) {
this.pk = pk;
}
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
public String getLang() {
return lang;
}
public void setLang(String lang) {
this.lang = lang;
}
public Long getOcc() {
return occ;
}
public void setOcc(Long occ) {
this.occ = occ;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
and this is the used class bridge
Code:
public class CollectDetailBridge implements FieldBridge {
public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
CollectDetail detail = (CollectDetail) value;
String tag = detail.getTag();
String lang = detail.getLang();
Long occ = detail.getOcc();
String content = detail.getContent();
String fieldName = getFieldName(name, tag, lang);
Field field = new Field(fieldName, content, luceneOptions.getStore(),
luceneOptions.getIndex(), luceneOptions.getTermVector() );
field.setBoost( luceneOptions.getBoost() );
document.add( field );
}
private String getFieldName(String name, String tag, String lang) {
if (lang.equals(""))
return name+"."+tag;
else
return name+"."+tag+"_"+lang;
}
}
The query code goes as follows:
Code:
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("pu");
EntityManager em = entityManagerFactory.createEntityManager();
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);
em.getTransaction().begin();
QueryBuilder qb = fullTextEntityManager.getSearchFactory()
.buildQueryBuilder().forEntity( CollectDetail.class ).get();
org.apache.lucene.search.Query query = qb.keyword()
.onFields("detail.BE_en")
.matching("test")
.createQuery();
// wrap Lucene query in a javax.persistence.Query
Query persistenceQuery = fullTextEntityManager.createFullTextQuery(query, CollectDetail.class).setMaxResults(100);
// execute search
List<CollectDetail> result = persistenceQuery.getResultList();
System.out.println(result.size());
em.getTransaction().commit();
em.close();
Is this not possible with Hibernate Search or am I missing something?
Thanks
Matthias