Hibernate Search filters that utilize enableFullTextFilter are not logged. Currently, the only logs I could find to my executing query are related to the org.apache.lucene.search.Query instance and not the org.hibernate.search.jpa.FullTextQuery instance. See below for related logs.
(LazyQueryState:99) - HSEARCH000274: Executing Lucene query '+ConstantScore(title:egg^5.0 summary:egg^2.0)'
Ideally, LazyQueryState query could be updated to provide a more complete solution for logging. Maybe output that could be plugged directly into Luke would be the best? My quick and dirty workaround is provided below.
private String getQueryExplanationText(org.hibernate.search.jpa.FullTextQuery fullTextQuery) {
StringBuffer sb = new StringBuffer();
String newLine = System.getProperty("line.separator");
fullTextQuery.setProjection(FullTextQuery.DOCUMENT_ID,
FullTextQuery.EXPLANATION,
FullTextQuery.THIS);
@SuppressWarnings("unchecked")
List<Object[]> results = fullTextQuery.getResultList();
for (Object[] result : results) {
Explanation e = (Explanation) result[1];
sb.append(e.toString());
sb.append(newLine);
}
fullTextQuery.setProjection();
try
{
FullTextQueryImpl fullTextQueryImpl = (org.hibernate.search.query.hibernate.impl.FullTextQueryImpl)fullTextQuery;
Field hSearchQueryField = fullTextQueryImpl.getClass().getDeclaredField("hSearchQuery");
hSearchQueryField.setAccessible(true);
org.hibernate.search.query.engine.impl.LuceneHSQuery luceneHSQuery = (org.hibernate.search.query.engine.impl.LuceneHSQuery)
hSearchQueryField.get(fullTextQueryImpl);
Method luceneHSQueryCreateFiltersMethod = luceneHSQuery.getClass().getDeclaredMethod("createFilters");
luceneHSQueryCreateFiltersMethod.setAccessible(true);
org.hibernate.search.query.engine.impl.QueryFilters queryFilters = (org.hibernate.search.query.engine.impl.QueryFilters)
luceneHSQueryCreateFiltersMethod.invoke(luceneHSQuery);
sb.append(queryFilters.getFilterQueries().toString());
sb.append(newLine);
}catch (Exception e) {
LOGGER.error("Failed to get Query Explanation Text", e);
}
return sb.toString();
}
|