Interface LuceneQueryModifier

All Known Implementing Classes:
DefaultLuceneQueryModifier

public interface LuceneQueryModifier
This class will clone the Query and add a MatchAllDocsQuery to the portion of the query that require them.

This inspects the query to determine if there are any nodes in the query that are marked as BooleanClause.Occur.MUST_NOT AND they do not have a positive query to work against.

This is because Lucene will drop queries of this kind instead of trying to find the correct result.

When we specify a query that is -A || B lucene treats this as equivalent to B. When we specify this query what we mean is (-A invalid input: '&'invalid input: '&' ALL_VALUES) || B which is obviously not equivalent to B.

The algorithm for determining if a BooleanQuery should have a MatchAllDocsQuery added to it with an occurrence of BooleanClause.Occur.MUST_NOT is:

Case 1: BooleanQuery contains only BooleanClause.Occur.MUST_NOT clauses THEN add a MatchAllDocsQuery

Case 2: BooleanQuery contains at least one BooleanClause.Occur.MUST or BooleanClause.Occur.FILTER THEN do not add a MatchAllDocsQuery since the MUST/FILTER portion of the query will provide a positive set of results

Case 3: BooleanQuery contains at least one BooleanClause.Occur.SHOULD and no BooleanClause.Occur.MUST or BooleanClause.Occur.FILTER THEN add a MatchAllDocsQuery to each BooleanClause.Occur.MUST_NOT portion of the query. This may mean that we need to rewrite a single term to be a BooleanQuery that contains the single term AND the MatchAllDocsQuery.

Since:
v4.0
  • Method Summary

    Modifier and Type
    Method
    Description
    org.apache.lucene.search.Query
    getModifiedQuery(org.apache.lucene.search.Query originalQuery)
    Will clone and rewrite the query as per the rules defined above.
  • Method Details

    • getModifiedQuery

      org.apache.lucene.search.Query getModifiedQuery(org.apache.lucene.search.Query originalQuery)
      Will clone and rewrite the query as per the rules defined above.
      Parameters:
      originalQuery - defines the lucene query to inspect, must not be null.
      Returns:
      the modified query that will return the right results when run.