[ 
https://issues.apache.org/jira/browse/LUCENE-4890?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13615472#comment-13615472
 ] 

Philip Searle commented on LUCENE-4890:
---------------------------------------

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();}}
                
> 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.
> {code:title=example.java|borderStyle=solid}
> /* 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");
> {code}

--
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