We're updating the issue view to help you get more done. 

Include enabled full-text filters when logging full-text queries

Description

Hibernate Search filters that utilize enableFullTextFilter are not logged.

Instead, we only log the query before full text filters are applied to it:

LazyQueryState.java

1 2 3 4 5 public void search(final QueryFilters filters, final Collector collector) throws IOException { validateQuery(); QUERY_LOG.executingLuceneQuery( userQuery ); searcher.search( filters.filterOrPassthrough( rewrittenQuery() ), collector ); }

Which results in this, ignoring the full-text filter(s):

1 (LazyQueryState:99) - HSEARCH000274: Executing Lucene query '+ConstantScore(title:egg^5.0 summary:egg^2.0)'

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?

Workaround

My quick and dirty workaround is provided below.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 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); LuceneHSQuery luceneHSQuery = (org.hibernate.search.query.engine.impl.LuceneHSQuery)hSearchQueryField.get(fullTextQueryImpl); Method luceneHSQueryCreateFiltersMethod = luceneHSQuery.getClass().getDeclaredMethod("createFilters"); luceneHSQueryCreateFiltersMethod.setAccessible(true); 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(); }

Environment

  • Windows 10

  • Wildfly 14.0.1.Final

Status

Assignee

Unassigned

Reporter

Mark S

Labels

None

Suitable for new contributors

None

Pull Request

None

Feedback Requested

None

Components

Fix versions

Affects versions

5.10.3.Final

Priority

Major