You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2021/01/06 17:58:45 UTC

[GitHub] [lucene-solr] kwatters commented on a change in pull request #1954: SOLR-14787 - Adding support to use inequalities to the payload check query parser.

kwatters commented on a change in pull request #1954:
URL: https://github.com/apache/lucene-solr/pull/1954#discussion_r552863407



##########
File path: lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadMatcherFactory.java
##########
@@ -0,0 +1,243 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.queries.payloads;
+
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+
+import org.apache.lucene.queries.payloads.SpanPayloadCheckQuery.PayloadType;
+import org.apache.lucene.util.BytesRef;
+
+/**
+ * Creates a payload matcher object based on a payload type and an operation.
+ * PayloadTypes of INT,FLOAT, or STRING are supported.  Inequality operations are supported.
+ */
+public class PayloadMatcherFactory {
+
+  private static final HashMap<PayloadType, HashMap<String, PayloadMatcher>> payloadCheckerOpTypeMap;
+  static {
+    payloadCheckerOpTypeMap= new HashMap<PayloadType, HashMap<String, PayloadMatcher>>();
+    // ints
+    HashMap<String, PayloadMatcher> intCheckers = new HashMap<String, PayloadMatcher>();
+    intCheckers.put("lt", new LTIntPayloadMatcher());
+    intCheckers.put("lte", new LTEIntPayloadMatcher());
+    intCheckers.put("gt", new GTIntPayloadMatcher());
+    intCheckers.put("gte", new GTEIntPayloadMatcher());
+    HashMap<String, PayloadMatcher> floatCheckers = new HashMap<String, PayloadMatcher>();
+    floatCheckers.put("lt", new LTFloatPayloadMatcher());
+    floatCheckers.put("lte", new LTEFloatPayloadMatcher());
+    floatCheckers.put("gt", new GTFloatPayloadMatcher());
+    floatCheckers.put("gte", new GTEFloatPayloadMatcher());
+    // strings
+    HashMap<String, PayloadMatcher> stringCheckers = new HashMap<String, PayloadMatcher>();
+    stringCheckers.put("lt", new LTStringPayloadMatcher());
+    stringCheckers.put("lte", new LTEStringPayloadMatcher());
+    stringCheckers.put("gt", new GTStringPayloadMatcher());
+    stringCheckers.put("gte", new GTEStringPayloadMatcher());
+    // load the matcher maps per payload type
+    payloadCheckerOpTypeMap.put(PayloadType.INT, intCheckers);
+    payloadCheckerOpTypeMap.put(PayloadType.FLOAT, floatCheckers);
+    payloadCheckerOpTypeMap.put(PayloadType.STRING, stringCheckers);
+  }
+  
+  /**
+   * Return a payload matcher for use in the SpanPayloadCheckQuery that will decode the ByteRef from 
+   * a payload based on the payload type, and apply a matching inequality operations (eq,lt,lte,gt,and gte)
+   * 
+   * @param payloadType the type of the payload to decode, STRING, INT, FLOAT
+   * @param op and inequalit operation as the test (example: eq for equals, gt for greater than)
+   * @return a payload matcher that decodes the payload and applies the operation inequality test.
+   * 
+   */
+  public static PayloadMatcher createMatcherForOpAndType(PayloadType payloadType, String op) {
+    // special optimization, binary/byte comparison
+    if (op == null || "eq".contentEquals(op)) {
+      return new EQPayloadMatcher();
+    }
+    // otherwise, we need to pay attention to the payload type and operation
+    return payloadCheckerOpTypeMap.get(payloadType).get(op);

Review comment:
       added a null test to default to unknown operations resulting in an equality comparison.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org