Uploaded image for project: 'Hibernate Search'
  1. HSEARCH-3459

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

    Details

      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
      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):

      (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.

      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();
      }
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              marks1900-user Mark S
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: