use of org.janusgraph.core.JanusGraphQuery in project janusgraph by JanusGraph.
the class JanusGraphStep method buildGraphCentricQuery.
private GraphCentricQuery buildGraphCentricQuery(final JanusGraphTransaction tx, final Entry<List<HasContainer>, QueryInfo> containers, final QueryProfiler queryProfiler) {
final JanusGraphQuery query = tx.query();
addConstraint(query, containers.getKey());
final List<OrderEntry> realOrders = orders.isEmpty() ? containers.getValue().getOrders() : orders;
for (final OrderEntry order : realOrders) query.orderBy(order.key, order.order);
if (highLimit != BaseQuery.NO_LIMIT || containers.getValue().getHighLimit() != BaseQuery.NO_LIMIT)
query.limit(Math.min(containers.getValue().getHighLimit(), highLimit));
return buildGraphCentricQuery(query, queryProfiler);
}
use of org.janusgraph.core.JanusGraphQuery in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method checkIndexingCounts.
private void checkIndexingCounts(String[] words, int numV, int originalNumV, boolean checkOrder) {
for (final String word : words) {
final int expectedSize = numV / words.length;
assertCount(expectedSize, tx.query().has("text", Text.CONTAINS, word).vertices());
assertCount(expectedSize, tx.query().has("text", Text.CONTAINS, word).edges());
// Test ordering
if (checkOrder) {
for (final String orderKey : new String[] { "time", "category" }) {
for (final Order order : Order.values()) {
for (final JanusGraphQuery traversal : ImmutableList.of(tx.query().has("text", Text.CONTAINS, word).orderBy(orderKey, order.getTP()), tx.query().has("text", Text.CONTAINS, word).orderBy(orderKey, order.getTP()))) {
verifyElementOrder(traversal.vertices(), orderKey, order, expectedSize);
}
}
}
}
}
assertCount(3, tx.query().has("group", 3).orderBy("time", asc).limit(3).vertices());
assertCount(3, tx.query().has("group", 3).orderBy("time", desc).limit(3).edges());
for (int i = 0; i < numV / 2; i += numV / 10) {
assertCount(i, tx.query().has("time", Cmp.GREATER_THAN_EQUAL, i).has("time", Cmp.LESS_THAN, i + i).vertices());
assertCount(i, tx.query().has("time", Cmp.GREATER_THAN_EQUAL, i).has("time", Cmp.LESS_THAN, i + i).edges());
}
for (int i = 0; i < numV; i += 5) {
testGeo(i, originalNumV, numV);
}
// Queries combining mixed and composite indexes
assertCount(4, tx.query().has("category", 1).interval("time", 10, 28).vertices());
assertCount(4, tx.query().has("category", 1).interval("time", 10, 28).edges());
assertCount(5, tx.query().has("time", Cmp.GREATER_THAN_EQUAL, 10).has("time", Cmp.LESS_THAN, 30).has("text", Text.CONTAINS, words[0]).vertices());
final double offset = (19 * 50.0 / originalNumV);
final double distance = Geoshape.point(0.0, 0.0).getPoint().distance(Geoshape.point(offset, offset).getPoint()) + 20;
assertCount(5, tx.query().has("location", Geo.INTERSECT, Geoshape.circle(0.0, 0.0, distance)).has("text", Text.CONTAINS, words[0]).vertices());
assertCount(5, tx.query().has("boundary", Geo.INTERSECT, Geoshape.circle(0.0, 0.0, distance)).has("text", Text.CONTAINS, words[0]).vertices());
assertCount(numV, tx.query().vertices());
assertCount(numV, tx.query().edges());
assertCount(numV / words.length, tx.query().has("name", Cmp.GREATER_THAN_EQUAL, "world").vertices());
assertCount(numV / words.length, tx.query().has("name", Cmp.GREATER_THAN_EQUAL, "world").edges());
assertCount(0, tx.query().has("name", Cmp.GREATER_THAN, "world").vertices());
assertCount(0, tx.query().has("name", Cmp.GREATER_THAN, "world").edges());
assertCount(numV - numV / words.length, tx.query().has("name", Cmp.LESS_THAN, "world").vertices());
assertCount(numV - numV / words.length, tx.query().has("name", Cmp.LESS_THAN, "world").edges());
assertCount(numV, tx.query().has("name", Cmp.LESS_THAN_EQUAL, "world").vertices());
assertCount(numV, tx.query().has("name", Cmp.LESS_THAN_EQUAL, "world").edges());
}
use of org.janusgraph.core.JanusGraphQuery in project janusgraph by JanusGraph.
the class JanusGraphStep method buildGlobalGraphCentricQuery.
private GraphCentricQuery buildGlobalGraphCentricQuery(final JanusGraphTransaction tx, final QueryProfiler globalQueryProfiler) {
Integer limit = null;
for (Map<List<HasContainer>, QueryInfo> containers : hasLocalContainers.values()) {
for (QueryInfo queryInfo : containers.values()) {
if (queryInfo.getLowLimit() > 0 || orders.isEmpty() && !queryInfo.getOrders().isEmpty()) {
return null;
}
final int currentHighLimit = queryInfo.getHighLimit();
if (limit == null) {
limit = currentHighLimit;
} else if (currentHighLimit < highLimit && !limit.equals(currentHighLimit)) {
return null;
}
}
}
final JanusGraphQuery query = tx.query();
for (Map<List<HasContainer>, QueryInfo> lc : hasLocalContainers.values()) {
List<JanusGraphQuery> localQueries = new ArrayList<>(lc.size());
for (final List<HasContainer> localContainers : lc.keySet()) {
final JanusGraphQuery localQuery = tx.query();
addConstraint(localQuery, localContainers);
localQueries.add(localQuery);
}
query.or(localQueries);
}
for (final OrderEntry order : orders) query.orderBy(order.key, order.order);
query.limit(Math.min(limit, highLimit));
return buildGraphCentricQuery(query, globalQueryProfiler);
}
Aggregations