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, Trunk
    • 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

        Hide
        ASF subversion and git services added a comment -

        Commit 1579717 from Michael McCandless in branch 'dev/branches/lucene_solr_3_6'
        [ https://svn.apache.org/r1579717 ]

        LUCENE-4890: get this test passing again

        Show
        ASF subversion and git services added a comment - Commit 1579717 from Michael McCandless in branch 'dev/branches/lucene_solr_3_6' [ https://svn.apache.org/r1579717 ] LUCENE-4890 : get this test passing again
        Hide
        Steve Rowe added a comment -

        Bulk close resolved 4.4 issues

        Show
        Steve Rowe added a comment - Bulk close resolved 4.4 issues
        Hide
        Adriano Crestani added a comment -

        Thanks Philip!

        Your logic sounds right! I created a test case and it ran just like you said.

        Here is the fix. I plan to commit in the next couple of days.

        Show
        Adriano Crestani added a comment - Thanks Philip! Your logic sounds right! I created a test case and it ran just like you said. Here is the fix. I plan to commit in the next couple of days.
        Hide
        Philip Searle added a comment -

        The issue appears to be due to the code that walks the query node's class hierarchy incorrectly getting the list of implemented interfaces from the most-derived class, instead of the class currently being processed.

        It can be fixed by changing the following line in QueryTreeBuilder.java from:
        Class<?>[] classes = node.getClass().getInterfaces();
        to:
        Class<?>[] classes = clazz.getInterfaces();

        Show
        Philip Searle added a comment - The issue appears to be due to the code that walks the query node's class hierarchy incorrectly getting the list of implemented interfaces from the most-derived class, instead of the class currently being processed. It can be fixed by changing the following line in QueryTreeBuilder.java from: Class<?>[] classes = node.getClass().getInterfaces(); to: Class<?>[] classes = clazz.getInterfaces();
        Hide
        Philip Searle added a comment -

        Improved example formatting.

        Show
        Philip Searle added a comment - Improved example formatting.

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development