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

ConstantScoreQuery etc have crazy toString()'s

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 5.1, 6.0
    • Component/s: None
    • Labels:
      None
    • Lucene Fields:
      New

      Description

      For backwards compatibility reasons, LUCENE-1518 gave Filter a default "crap" toString(String) impl of getClass().getSimpleName(). I don't think we should do this. It causes problems e.g. when filters are wrapped in ConstantScoreQuery or other places, because toString(String) does the wrong thing.

      Filter f = new MultiTermQueryWrapperFilter<WildcardQuery>(new WildcardQuery(new Term("foo", "b*ar")));
          
      System.out.println(f.toString()); // foo:b*ar
      System.out.println(f.toString("foo")); // MultiTermQueryWrapperFilter
      

      Instead i think that impl should be removed (leaving it abstract), and Query.toString() should be final for a hard break:

        /** Prints a query to a string, with <code>field</code> assumed to be the 
         * default field and omitted.
         */
        public abstract String toString(String field);
      
        /** Prints a query to a string. */
        @Override
        public ****final**** String toString() {
          return toString("");
        }
      

      having buggy toString's is worse than requiring a change in custom filters. It impacts all users rather than just expert ones. Also by doing this, all the current toString bugs in the codebase show up as compile errors.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              rcmuir Robert Muir
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: