Thanks everyone for the previous help.
3.2.6 GA
Mapping documents:
Code:
@Indexed(index="AuditTrail")
public class AuditTrail implements Serializable {
private static final long serialVersionUID = 54324L;
@DocumentId
private Integer id;
@Field(index=Index.TOKENIZED, store=Store.YES)
@Analyzer(impl=KeywordAnalyzer.class)
@Boost(value=2)
private String function;
@Field(index=Index.TOKENIZED, store=Store.YES)
@Analyzer(impl=KeywordAnalyzer.class)
@Boost(value=2)
private String attribute;
@Field(index=Index.TOKENIZED, store=Store.YES)
@Analyzer(impl=KeywordAnalyzer.class)
@Boost(value=2)
private String oldValue;
@Field(index=Index.TOKENIZED, store=Store.YES)
@Analyzer(impl=KeywordAnalyzer.class)
@Boost(value=2)
private String newValue;
// getters and setters
}
Code between sessionFactory.openSession() and session.close():Code:
@Override
public List<AuditTrail> getBySearch(final String searchTerm, final String[] fields,
final int startPos, final int maxSize) {
return forceGenericList(getHibernateTemplate().executeWithNativeSession(
new HibernateCallback()
{
public Object doInHibernate(Session session) throws HibernateException
{
try
{
FullTextSession fullTextSession = Search.createFullTextSession(session);
QueryParser parser = new MultiFieldQueryParser(fields, new SnowballAnalyzer("English"));
Query query = parser.parse(searchTerm);
org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery(query,AuditTrail.class);
fullTextQuery.setFirstResult(startPos);
fullTextQuery.setMaxResults(maxSize);
return fullTextQuery.list();
}
catch (ParseException pe)
{
return new LinkedList<AuditTrail>();
}
}
}));
}
my test case.
Code:
@Test
public void testSearchAuditedTrail()
{
final int sizeBefore1 = this.auditTrailService.searchAuditedTrail("some stuff", new String[]{"oldValue", "newValue", "note"}).size();
final int sizeBefore2 = this.auditTrailService.searchAuditedTrail("admin", new String[]{"createBy.username", "function"}).size();
this.auditTrailService.log(this.auditTrail, this.auditTrail2, this.user, "some stuff");
Assert.assertEquals(this.auditTrailService.searchAuditedTrail("some stuff", new String[]{"date"}).size(), 0);
Assert.assertEquals(this.auditTrailService.searchAuditedTrail("some stuff", new String[]{"oldValue", "newValue", "note"}).size(), (sizeBefore1+1));
Assert.assertEquals(this.auditTrailService.searchAuditedTrail(this.user.getUsername(), new String[]{"createBy.username", "function"}).size(),(sizeBefore2+1));
}
the service is just wrapper around the dao. I check the results and it happens to be 0. What is wrong? I check the index and they are created.