Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-4376

Add Query subclasses for selecting documents where a field is empty or not

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Duplicate
    • None
    • 6.0
    • core/query/scoring
    • None
    • New

    Description

      Users frequently wish to select documents based on whether a specified sparsely-populated field has a value or not. Lucene should provide specific Query subclasses that optimize for these two cases, rather than force users to guess what workaround might be most efficient. It is simplest for users to use a simple pure wildcard term to check for non-empty fields or a negated pure wildcard term to check for empty fields, but it has been suggested that this can be rather inefficient, especially for text fields with many terms.

      1. Add NonEmptyFieldQuery - selects all documents that have a value for the specified field.
      2. Add EmptyFieldQuery - selects all documents that do not have a value for the specified field.

      The query parsers could turn a pure wildcard query (asterisk only) into a NonEmptyFieldQuery, and a negated pure wildcard query into an EmptyFieldQuery.

      Alternatively, maybe PrefixQuery could detect pure wildcard and automatically "rewrite" it into NonEmptyFieldQuery.

      My assumption is that if the actual values of the field are not needed, Lucene can much more efficiently simply detect whether values are present, rather than, for example, the user having to create a separate boolean "has value" field that they would query for true or false.

      Attachments

        Activity

          People

            Unassigned Unassigned
            jkrupan Jack Krupansky
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: