Commit 1b41b980 by chaitali borole Committed by kevalbhatt

ATLAS-3892 : Basic search enhanced Feature - Search history

Signed-off-by: 's avatarkevalbhatt <kbhatt@apache.org>
parent 83e9c21f
...@@ -188,6 +188,7 @@ public final class Constants { ...@@ -188,6 +188,7 @@ public final class Constants {
public static final String TERM_ASSIGNMENT_LABEL = "r:AtlasGlossarySemanticAssignment"; public static final String TERM_ASSIGNMENT_LABEL = "r:AtlasGlossarySemanticAssignment";
public static final String ATTRIBUTE_INDEX_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "index"); public static final String ATTRIBUTE_INDEX_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "index");
public static final String ATTRIBUTE_KEY_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "key"); public static final String ATTRIBUTE_KEY_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "key");
public static final String ATTRIBUTE_VALUE_DELIMITER = ",";
public static final String VERTEX_ID_IN_IMPORT_KEY = "__vIdInImport"; public static final String VERTEX_ID_IN_IMPORT_KEY = "__vIdInImport";
public static final String EDGE_ID_IN_IMPORT_KEY = "__eIdInImport"; public static final String EDGE_ID_IN_IMPORT_KEY = "__eIdInImport";
......
...@@ -443,6 +443,10 @@ public class SearchParameters implements Serializable { ...@@ -443,6 +443,10 @@ public class SearchParameters implements Serializable {
* Logical comparision operators can only be used with numbers or dates * Logical comparision operators can only be used with numbers or dates
* IN, LIKE, startsWith, endsWith, CONTAINS can only be used with strings or text * IN, LIKE, startsWith, endsWith, CONTAINS can only be used with strings or text
*/ */
/**
* NOTE : The names added in the String array should always contain first value in lower case
*/
public enum Operator { public enum Operator {
LT(new String[]{"<", "lt"}), LT(new String[]{"<", "lt"}),
GT(new String[]{">", "gt"}), GT(new String[]{">", "gt"}),
...@@ -460,6 +464,7 @@ public class SearchParameters implements Serializable { ...@@ -460,6 +464,7 @@ public class SearchParameters implements Serializable {
CONTAINS_ALL(new String[]{"containsAll", "CONTAINSALL", "contains_all", "CONTAINS_ALL"}), CONTAINS_ALL(new String[]{"containsAll", "CONTAINSALL", "contains_all", "CONTAINS_ALL"}),
IS_NULL(new String[]{"isNull", "ISNULL", "is_null", "IS_NULL"}), IS_NULL(new String[]{"isNull", "ISNULL", "is_null", "IS_NULL"}),
NOT_NULL(new String[]{"notNull", "NOTNULL", "not_null", "NOT_NULL"}), NOT_NULL(new String[]{"notNull", "NOTNULL", "not_null", "NOT_NULL"}),
TIME_RANGE(new String[]{"timerange", "TIMERANGE","time_range","TIME_RANGE"})
; ;
static final Map<String, Operator> operatorsMap = new HashMap<>(); static final Map<String, Operator> operatorsMap = new HashMap<>();
......
...@@ -179,6 +179,40 @@ public class SearchPredicateUtil { ...@@ -179,6 +179,40 @@ public class SearchPredicateUtil {
return ret; return ret;
} }
public static ElementAttributePredicateGenerator getInRangePredicateGenerator() {
if (LOG.isDebugEnabled()) {
LOG.debug("==> getInRangePredicateGenerator");
}
ElementAttributePredicateGenerator ret = new ElementAttributePredicateGenerator() {
@Override
public Predicate generatePredicate(String attrName, Object attrVal, Class attrClass) {
return generatePredicate(attrName, attrVal, attrVal, attrClass);
}
@Override
public Predicate generatePredicate(String attrName, Object attrVal, Object attrVal2, Class attrClass) {
final Predicate ret;
if (attrName == null || attrClass == null || attrVal == null || attrVal2 == null) {
ret = ALWAYS_FALSE;
} else if (Long.class.isAssignableFrom(attrClass)) {
ret = LongPredicate.getInRangePredicate(attrName, attrClass, (Long) attrVal, (Long) attrVal2);
} else {
ret = ALWAYS_FALSE;
}
return ret;
}
};
if (LOG.isDebugEnabled()) {
LOG.debug("<== getInRangePredicateGenerator");
}
return ret;
}
public static ElementAttributePredicateGenerator getGTEPredicateGenerator() { public static ElementAttributePredicateGenerator getGTEPredicateGenerator() {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("==> getGTEPredicateGenerator"); LOG.debug("==> getGTEPredicateGenerator");
...@@ -768,6 +802,9 @@ public class SearchPredicateUtil { ...@@ -768,6 +802,9 @@ public class SearchPredicateUtil {
public interface ElementAttributePredicateGenerator { public interface ElementAttributePredicateGenerator {
Predicate generatePredicate(String attrName, Object attrVal, Class attrClass); Predicate generatePredicate(String attrName, Object attrVal, Class attrClass);
default Predicate generatePredicate(String attrName, Object attrVal, Object attrVal2, Class attrClass) {
return generatePredicate(attrName, attrVal, attrClass);
}
} }
static abstract class ElementAttributePredicate implements Predicate { static abstract class ElementAttributePredicate implements Predicate {
...@@ -969,16 +1006,27 @@ public class SearchPredicateUtil { ...@@ -969,16 +1006,27 @@ public class SearchPredicateUtil {
static abstract class LongPredicate extends ElementAttributePredicate { static abstract class LongPredicate extends ElementAttributePredicate {
final Long value; final Long value;
final Long value2;
LongPredicate(String attrName, Class attrClass, Long value) { LongPredicate(String attrName, Class attrClass, Long value) {
super(attrName, attrClass); super(attrName, attrClass);
this.value = value; this.value = value;
this.value2 = null;
} }
LongPredicate(String attrName, Class attrClass, Long value, boolean isNullValid) { LongPredicate(String attrName, Class attrClass, Long value, Long value2, boolean isNullValid) {
super(attrName, attrClass, isNullValid); super(attrName, attrClass, isNullValid);
this.value = value; this.value = value;
this.value2 = value2;
}
LongPredicate(String attrName, Class attrClass, Long value, boolean isNullValid) {
super(attrName, attrClass, isNullValid);
this.value = value;
this.value2 = null;
} }
static ElementAttributePredicate getEQPredicate(String attrName, Class attrClass, Long value) { static ElementAttributePredicate getEQPredicate(String attrName, Class attrClass, Long value) {
...@@ -1028,6 +1076,14 @@ public class SearchPredicateUtil { ...@@ -1028,6 +1076,14 @@ public class SearchPredicateUtil {
} }
}; };
} }
static ElementAttributePredicate getInRangePredicate(String attrName, Class attrClass, Long rangeStart, Long rangeEnd) {
return new LongPredicate(attrName, attrClass, rangeStart, rangeEnd, false) {
protected boolean compareValue(Object vertexAttrVal) {
return ((Long) vertexAttrVal).compareTo(value) >= 0 && ((Long) vertexAttrVal).compareTo(value2) <= 0;
}
};
}
} }
static abstract class FloatPredicate extends ElementAttributePredicate { static abstract class FloatPredicate extends ElementAttributePredicate {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment