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. For example:
{code:java|title=LazyQueryState.java} public void search(final QueryFilters filters, final Collector collector) throws IOException { validateQuery(); QUERY_LOG.executingLuceneQuery( userQuery ); searcher.search( filters.filterOrPassthrough( rewrittenQuery() ), collector ); } {code} Which provides the only query related logging I have thus far found. {code} (LazyQueryState:99) - HSEARCH000274: Executing Lucene query '+ConstantScore(title:egg^5.0 summary:egg^2.0)' {code}
h3. Suggested Solution
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?
h3. Workaround
My quick and dirty workaround is provided below. {code:java} 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(); } {code} |
|