I have found the following output from Search: -
Code:
12/08/22 12:17:16 INFO impl.SimpleIndexingProgressMonitor: HSEARCH000027: Going to reindex 0 entities
12/08/22 12:17:16 INFO impl.SimpleIndexingProgressMonitor: HSEARCH000027: Going to reindex 0 entities
12/08/22 12:17:16 INFO impl.SimpleIndexingProgressMonitor: HSEARCH000028: Reindexed 0 entities
12/08/22 12:17:16 INFO impl.SimpleIndexingProgressMonitor: HSEARCH000027: Going to reindex 0 entities
12/08/22 12:17:16 INFO impl.SimpleIndexingProgressMonitor: HSEARCH000027: Going to reindex 0 entities
12/08/22 12:17:16 INFO impl.SimpleIndexingProgressMonitor: HSEARCH000028: Reindexed 0 entities
This suggests that the inserted data isn't found somehow (probably transaction related).
I tried @Transactional on the dbUnitAdapter.setup method in the hope that it would commit when the method is finished and therefore would be seen by the MassIndexer.
I also tried manually creating a transaction like so: -
Code:
@Before
public void setup() throws Exception{
TransactionDefinition definition = new DefaultTransactionDefinition();
TransactionStatus transStatus = transactionManager.getTransaction(definition);
try {
dbUnitAdapter.setup("ClubDaoTest.xml");
transactionManager.commit(transStatus);
}
catch (Exception ex) {
transactionManager.rollback(transStatus);
throw ex;
}
searchIndexer.doIndexing();
super.before();
}
Alas, this didn't work either.
After I insert the data I can do hibernate queries on it successfully (there are other non-search tests in the JUnit class).
Here is my search code (this works, just not in unit tests)
Code:
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);
QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder()
.forEntity(Club.class).get();
org.apache.lucene.search.Query query = qb.keyword()
.onFields("name", "address1", "address2", "town", "county", "country", "attrValues.value")
.matching(searchString).createQuery();
BooleanJunction<BooleanJunction> b = qb.bool();
b.must(query);
b.must(qb.range().onField("lft").above(parentClub.getLft()).createQuery());
b.must(qb.range().onField("lft").below(parentClub.getRgt()).createQuery());
// wrap Lucene query in a javax.persistence.Query
javax.persistence.Query persistenceQuery = fullTextEntityManager.createFullTextQuery(b.createQuery(),
Club.class);
persistenceQuery.setFirstResult((Integer) params.get(SQLQueryConstants.RECORD_INDEX))
.setMaxResults((Integer) params.get(SQLQueryConstants.OBJECTS_PER_PAGE));
// execute search
result = persistenceQuery.getResultList();
Thanks for your help!
All the best,
Ash