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