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

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

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 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
    • 3.6.3, 4.4, 6.0
    • core/queryparser
    • None
    • Lucene 3.3.0 on Win32

    • 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");
      

      Attachments

        1. LUCENE-4890_2013_05_25.patch
          3 kB
          Adriano Crestani

        Activity

          People

            adriano_crestani Adriano Crestani
            philip.searle Philip Searle
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: