Philip Searle created LUCENE-4890:
-------------------------------------

             Summary: QueryTreeBuilder.getBuilder() only finds interfaces on 
the most derived class
                 Key: LUCENE-4890
                 URL: https://issues.apache.org/jira/browse/LUCENE-4890
             Project: Lucene - Core
          Issue Type: Bug
          Components: core/queryparser
    Affects Versions: 3.3
         Environment: Lucene 3.3.0 on Win32
            Reporter: Philip Searle
            Priority: Minor


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.

/* An example: */
/* 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");

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org

Reply via email to