Skip to content

Commit

Permalink
support P.textcontains() for rest-api query (#1312)
Browse files Browse the repository at this point in the history
how to use:
/graphs/hugegraph/graph/vertices?properties={"city":"P.textcontains(\"shanghai\")"}

improve: #1309
Change-Id: I2d7c0b8c58c6ac53cd6b99414859cb0510393f6c
  • Loading branch information
javeme authored Jan 5, 2021
1 parent af2590f commit 26ac664
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ public static Relation textContainsAny(Id key, Set<String> words) {
return new UserpropRelation(key, RelationType.TEXT_CONTAINS_ANY, words);
}

public static Condition contains(Id key, Object value) {
return new UserpropRelation(key, RelationType.CONTAINS, value);
}

/**
* Condition defines
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
import com.baidu.hugegraph.type.define.Action;
import com.baidu.hugegraph.type.define.HugeKeys;
import com.baidu.hugegraph.type.define.IndexType;
import com.baidu.hugegraph.type.define.SchemaStatus;
import com.baidu.hugegraph.util.CollectionUtil;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.InsertionOrderUtil;
Expand Down Expand Up @@ -1359,6 +1358,9 @@ private static NoIndexException noIndexException(HugeGraph graph,
if (query.hasNeqCondition()) {
mismatched.add("not-equal");
}
if (mismatched.isEmpty()) {
mismatched.add(query.relations().toString());
}
return new NoIndexException("Don't accept query based on properties " +
"%s that are not indexed in %s, " +
"may not match %s condition",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private ConditionP(final BiPredicate<Object, Object> predicate,
super(predicate, value);
}

public static ConditionP textContains(String value) {
public static ConditionP textContains(Object value) {
return new ConditionP(RelationType.TEXT_CONTAINS, value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,8 @@ public static P<Object> parsePredicate(String predicate) {
return P.outside(params[0], params[1]);
case "within":
return P.within(predicateArgs(value));
case "textcontains":
return ConditionP.textContains(predicateArg(value));
case "contains":
// Just for inner use case like auth filter
return ConditionP.contains(predicateArg(value));
Expand Down Expand Up @@ -868,6 +870,12 @@ public static Condition parsePredicate(PropertyKey pk, String predicate) {
validValues.add(validPropertyValue(v, pk));
}
return Condition.in(pk.id(), validValues);
case "textcontains":
validValue = validPropertyValue(value, pk);
return Condition.textContains(pk.id(), (String) validValue);
case "contains":
validValue = validPropertyValue(value, pk);
return Condition.contains(pk.id(), validValue);
default:
throw new NotSupportException("predicate '%s'", method);
}
Expand Down

0 comments on commit 26ac664

Please sign in to comment.