thelabdude commented on a change in pull request #173:
URL: https://github.com/apache/solr/pull/173#discussion_r651961736



##########
File path: solr/core/src/java/org/apache/solr/handler/sql/SolrFilter.java
##########
@@ -69,34 +78,81 @@ public void implement(Implementor implementor) {
 
   private static class Translator {
 
-    private final List<String> fieldNames;
+    protected final List<String> fieldNames;
     public boolean negativeQuery = true;
 
     Translator(List<String> fieldNames) {
       this.fieldNames = fieldNames;
     }
 
-    private String translateMatch(RexNode condition) {
-      if (condition.getKind().belongsTo(SqlKind.COMPARISON)) {
+    protected String translateMatch(RexNode condition) {
+      final SqlKind kind = condition.getKind();
+      if (kind.belongsTo(SqlKind.COMPARISON) || kind == SqlKind.NOT) {
         return translateComparison(condition);
       } else if (condition.isA(SqlKind.AND)) {
-        return "(" + translateAnd(condition) + ")";
+        // see if this is a translated range query of greater than or equals 
and less than or equal on same field
+        // if so, then collapse into a single range criteria, e.g. field:[gte 
TO lte] instead of two ranges AND'd together
+        RexCall call = (RexCall) condition;
+        List<RexNode> operands = call.getOperands();
+        return (operands.size() == 2 && operands.get(0).getKind() == 
SqlKind.GREATER_THAN_OR_EQUAL && operands.get(1).getKind() == 
SqlKind.LESS_THAN_OR_EQUAL)
+            ? translateRangeFilter(call) : "(" + translateAnd(condition) + ")";
       } else if (condition.isA(SqlKind.OR)) {
         return "(" + translateOr(condition) + ")";
+      } else if (kind == SqlKind.LIKE) {
+        return translateLike(condition, false);
+      } else if (kind == SqlKind.IS_NOT_NULL || kind == SqlKind.IS_NULL) {
+        return translateIsNullOrIsNotNull(condition);
       } else {
         return null;
       }
     }
 
-    private String translateOr(RexNode condition) {
+    protected String translateRangeFilter(RexCall andNode) {

Review comment:
       After completely botching this a few times, I think we have it sorted 
out. Thanks to @HoustonPutman for walking me through the seemingly simple 
nuances ;-)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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

Reply via email to