I tried unsuccessful to create an index for seed data in Seam. Only the index directories were created successfully during deployment. Here is the code to create a full index:
Code:
@Stateless
@Name("searchBean")
public class SearchBean implements Search {
@PersistenceContext
private EntityManager em;
@In(create=true)
private BusinessHome businessHome;
/**
* load and re-persist every entity that is indexed
*/
public void indexAll() {
List<Business> businesses = em.createQuery("from Business c")
.getResultList();
FullTextSession session = Search.createFullTextSession(((HibernateEntityManager) em.getDelegate()).getSession());
for (Business business : businesses) {
session.index(business);
}
return;
}
After some debugging, I found the indexing is failing at indexing the "categories" field of Business. This field is declared as such:
Code:
@Field(name="category", index=Index.TOKENIZED, store= Store.NO)
@FieldBridge(impl = CategoryBridge.class)
private List<Category> categories = new ArrayList<Category>(0);
By default the seed businesses have empty categories. Here is the objectToString(Object object) method of CategoryBridge.class:
Code:
public String objectToString(Object object) {
List<Category> cats = (List<Category>) object;
if (cats == null)
return null;
else {
StringBuffer sb = new StringBuffer(16);
for (Category cat : cats) {
sb.append(cat.getId()).append(", ");
if (cat.getParent() != null) {
sb.append(cat.getParent().getId()).append(", ");
}
}
return sb.toString();
}
}
However, if I update each record through UI, the index will get updated each time.
What am I doing wrong? Thanks.