Lucene - Core
  1. Lucene - Core
  2. LUCENE-4890

QueryTreeBuilder.getBuilder() only finds interfaces on the most derived class

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.9, 2.9.1, 2.9.2, 2.9.3, 2.9.4, 3.0, 3.0.1, 3.0.2, 3.0.3, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.6.1, 3.6.2
    • Fix Version/s: 3.6.3, 4.4, 5.0
    • Component/s: core/queryparser
    • Labels:
      None
    • Environment:

      Lucene 3.3.0 on Win32

    • Lucene Fields:
      New

      Description

      QueryBuilder implementations registered with QueryTreeBuilder.setBuilder() are not recognized by QueryTreeBuilder.getBuilder() if they are registered for an interface implemented by a superclass. Registering them for a concrete query node class or an interface implemented by the most-derived class do work.

      example.java
      /* Our custom query builder */
      class CustomQueryTreeBuilder extends QueryTreeBuilder {
        public CustomQueryTreeBuilder() {
          /* Turn field:"value" into an application-specific object */
          setBuilder(FieldQueryNode.class, new QueryBuilder() {
            @Override
            public Object build(QueryNode queryNode) {
              FieldQueryNode node = (FieldQueryNode) queryNode;
              return new ApplicationSpecificClass(node.getFieldAsString());
            }
          });
          /* Ignore all other query node types */
          setBuilder(QueryNode.class, new  QueryBuilder() {
            @Override
            public Object build(QueryNode queryNode) {
              return null;
            }
          });
        }
      }
      
      /* Assume this is in the main program: */
      StandardQueryParser queryParser = new StandardQueryParser();
      queryParser.setQueryBuilder(new CustomQueryTreeBuilder());
      
      /* The following line will throw an exception because it can't find a builder for BooleanQueryNode.class */
      Object queryObject = queryParser.parse("field:\"value\" field2:\"value2\"", "field");
      

        Activity

        No work has yet been logged on this issue.

          People

          • Assignee:
            Adriano Crestani
            Reporter:
            Philip Searle
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development