use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.
the class TraversalUtil method convOr.
public static Condition convOr(HugeGraph graph, HugeType type, HasContainer has) {
P<?> p = has.getPredicate();
assert p instanceof OrP;
@SuppressWarnings("unchecked") List<P<Object>> predicates = ((OrP<Object>) p).getPredicates();
if (predicates.size() < 2) {
throw newUnsupportedPredicate(p);
}
Condition cond = null;
for (P<Object> predicate : predicates) {
HasContainer newHas = new HasContainer(has.getKey(), predicate);
Condition newCond = convHas2Condition(newHas, type, graph);
if (cond == null) {
cond = newCond;
} else {
cond = Condition.or(newCond, cond);
}
}
return cond;
}
use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.
the class TraversalUtil method fillConditionQuery.
public static ConditionQuery fillConditionQuery(ConditionQuery query, List<HasContainer> hasContainers, HugeGraph graph) {
HugeType resultType = query.resultType();
for (HasContainer has : hasContainers) {
Condition condition = convHas2Condition(has, resultType, graph);
query.query(condition);
}
return query;
}
use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.
the class TraversalUtil method convHas2Condition.
public static Condition convHas2Condition(HasContainer has, HugeType type, HugeGraph graph) {
P<?> p = has.getPredicate();
E.checkArgument(p != null, "The predicate of has(%s) is null", has);
BiPredicate<?, ?> bp = p.getBiPredicate();
Condition condition;
if (keyForContainsKeyOrValue(has.getKey())) {
condition = convContains2Relation(graph, has);
} else if (bp instanceof Compare) {
condition = convCompare2Relation(graph, type, has);
} else if (bp instanceof RelationType) {
condition = convRelationType2Relation(graph, type, has);
} else if (bp instanceof Contains) {
condition = convIn2Relation(graph, type, has);
} else if (p instanceof AndP) {
condition = convAnd(graph, type, has);
} else if (p instanceof OrP) {
condition = convOr(graph, type, has);
} else {
// TODO: deal with other Predicate
throw newUnsupportedPredicate(p);
}
return condition;
}
use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.
the class TraversalUtil method convAnd.
public static Condition convAnd(HugeGraph graph, HugeType type, HasContainer has) {
P<?> p = has.getPredicate();
assert p instanceof AndP;
@SuppressWarnings("unchecked") List<P<Object>> predicates = ((AndP<Object>) p).getPredicates();
if (predicates.size() < 2) {
throw newUnsupportedPredicate(p);
}
Condition cond = null;
for (P<Object> predicate : predicates) {
HasContainer newHas = new HasContainer(has.getKey(), predicate);
Condition newCond = convHas2Condition(newHas, type, graph);
if (cond == null) {
cond = newCond;
} else {
cond = Condition.and(newCond, cond);
}
}
return cond;
}
use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.
the class GraphIndexTransaction method constructSearchQuery.
private ConditionQuery constructSearchQuery(ConditionQuery query, MatchedIndex index) {
ConditionQuery newQuery = query;
Set<Id> indexFields = new HashSet<>();
// Convert has(key, text) to has(key, textContainsAny(word1, word2))
for (IndexLabel il : index.indexLabels()) {
if (il.indexType() != IndexType.SEARCH) {
continue;
}
Id indexField = il.indexField();
String fieldValue = (String) newQuery.userpropValue(indexField);
Set<String> words = this.segmentWords(fieldValue);
indexFields.add(indexField);
newQuery = newQuery.copy();
newQuery.unsetCondition(indexField);
newQuery.query(Condition.textContainsAny(indexField, words));
}
// Register results filter to compare property value and search text
newQuery.registerResultsFilter(element -> {
assert element != null;
for (Condition cond : query.conditions()) {
Object key = cond.isRelation() ? ((Relation) cond).key() : null;
if (key instanceof Id && indexFields.contains(key)) {
// This is an index field of search index
Id field = (Id) key;
HugeProperty<?> property = element.getProperty(field);
String propValue = propertyValueToString(property.value());
String fieldValue = (String) query.userpropValue(field);
if (this.matchSearchIndexWords(propValue, fieldValue)) {
continue;
}
return false;
}
if (!cond.test(element)) {
return false;
}
}
return true;
});
return newQuery;
}
Aggregations