use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method addVertex.
private void addVertex(int time, String text, double height, String[] phones) {
newTx();
JanusGraphVertex v = tx.addVertex("text", text, "time", time, "height", height);
for (String phone : phones) {
v.property("phone", phone);
}
newTx();
}
use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method testContainsWithMultipleValues.
@Test
public // so we need to make sure that we don't apply AND twice.
void testContainsWithMultipleValues() {
PropertyKey name = makeKey("name", String.class);
mgmt.buildIndex("store1", Vertex.class).addKey(name).buildMixedIndex(INDEX);
mgmt.commit();
JanusGraphVertex v1 = tx.addVertex();
v1.property("name", "hercules was here");
tx.commit();
final JanusGraphVertex r = Iterables.get(graph.query().has("name", Text.CONTAINS, "hercules here").vertices(), 0);
Assert.assertEquals(r.property("name").value(), "hercules was here");
}
use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method testDateIndexing.
/**
* Tests indexing dates
*/
@Test
public void testDateIndexing() {
PropertyKey name = makeKey("date", Date.class);
mgmt.buildIndex("dateIndex", Vertex.class).addKey(name).buildMixedIndex(INDEX);
finishSchema();
clopen();
JanusGraphVertex v1 = graph.addVertex();
v1.property("date", new Date(1));
JanusGraphVertex v2 = graph.addVertex();
v2.property("date", new Date(2000));
assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.EQUAL, new Date(1))));
assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.GREATER_THAN, new Date(1))));
assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.GREATER_THAN_EQUAL, new Date(1)).vertices()));
assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.LESS_THAN, new Date(2000))));
assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.LESS_THAN_EQUAL, new Date(2000)).vertices()));
assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.NOT_EQUAL, new Date(1))));
// Flush the index
clopen();
assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.EQUAL, new Date(1))));
assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.GREATER_THAN, new Date(1))));
assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.GREATER_THAN_EQUAL, new Date(1)).vertices()));
assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.LESS_THAN, new Date(2000))));
assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.LESS_THAN_EQUAL, new Date(2000)).vertices()));
assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.NOT_EQUAL, new Date(1))));
}
use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method testIndexQueryWithScore.
@Test
public void testIndexQueryWithScore() {
PropertyKey textKey = mgmt.makePropertyKey("text").dataType(String.class).make();
mgmt.buildIndex("store1", Vertex.class).addKey(textKey).buildMixedIndex(INDEX);
mgmt.commit();
JanusGraphVertex v1 = tx.addVertex();
JanusGraphVertex v2 = tx.addVertex();
JanusGraphVertex v3 = tx.addVertex();
v1.property("text", "Hello Hello Hello Hello Hello Hello Hello Hello world");
v2.property("text", "Hello abab abab fsdfsd sfdfsd sdffs fsdsdf fdf fsdfsd aera fsad abab abab fsdfsd sfdf");
v3.property("text", "Hello Hello world world");
tx.commit();
final Set<Double> scores = graph.indexQuery("store1", "v.text:(Hello)").vertexStream().map(JanusGraphIndexQuery.Result::getScore).collect(Collectors.toSet());
Assert.assertEquals(3, scores.size());
}
use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method testIndexing.
@Test
public void testIndexing() throws InterruptedException {
PropertyKey text = makeKey("text", String.class);
createExternalVertexIndex(text, INDEX);
createExternalEdgeIndex(text, INDEX);
PropertyKey name = makeKey("name", String.class);
mgmt.addIndexKey(getExternalIndex(Vertex.class, INDEX), name, Parameter.of("mapping", Mapping.TEXT));
mgmt.addIndexKey(getExternalIndex(Edge.class, INDEX), name, Parameter.of("mapping", Mapping.TEXT));
PropertyKey location = makeKey("location", Geoshape.class);
createExternalVertexIndex(location, INDEX);
createExternalEdgeIndex(location, INDEX);
PropertyKey boundary = makeKey("boundary", Geoshape.class);
mgmt.addIndexKey(getExternalIndex(Vertex.class, INDEX), boundary, Parameter.of("mapping", Mapping.PREFIX_TREE), Parameter.of("index-geo-dist-error-pct", 0.0025));
mgmt.addIndexKey(getExternalIndex(Edge.class, INDEX), boundary, Parameter.of("mapping", Mapping.PREFIX_TREE), Parameter.of("index-geo-dist-error-pct", 0.0025));
PropertyKey time = makeKey("time", Long.class);
createExternalVertexIndex(time, INDEX);
createExternalEdgeIndex(time, INDEX);
PropertyKey category = makeKey("category", Integer.class);
mgmt.buildIndex("vcategory", Vertex.class).addKey(category).buildCompositeIndex();
mgmt.buildIndex("ecategory", Edge.class).addKey(category).buildCompositeIndex();
PropertyKey group = makeKey("group", Byte.class);
createExternalVertexIndex(group, INDEX);
createExternalEdgeIndex(group, INDEX);
makeVertexIndexedKey("uid", Integer.class);
((StandardEdgeLabelMaker) mgmt.makeEdgeLabel("knows")).sortKey(time).signature(location, boundary).make();
finishSchema();
clopen();
String[] words = { "world", "aurelius", "janusgraph", "graph" };
int numCategories = 5;
int numGroups = 10;
double distance, offset;
int numV = 100;
final int originalNumV = numV;
for (int i = 0; i < numV; i++) {
JanusGraphVertex v = tx.addVertex();
v.property(VertexProperty.Cardinality.single, "uid", i);
v.property(VertexProperty.Cardinality.single, "category", i % numCategories);
v.property(VertexProperty.Cardinality.single, "group", i % numGroups);
v.property(VertexProperty.Cardinality.single, "text", "Vertex " + words[i % words.length]);
v.property(VertexProperty.Cardinality.single, "name", words[i % words.length]);
v.property(VertexProperty.Cardinality.single, "time", i);
offset = (i % 2 == 0 ? 1 : -1) * (i * 50.0 / numV);
v.property(VertexProperty.Cardinality.single, "location", Geoshape.point(0.0 + offset, 0.0 + offset));
if (i % 2 == 0) {
v.property(VertexProperty.Cardinality.single, "boundary", Geoshape.line(Arrays.asList(new double[][] { { offset - 0.1, offset - 0.1 }, { offset + 0.1, offset - 0.1 }, { offset + 0.1, offset + 0.1 }, { offset - 0.1, offset + 0.1 } })));
} else {
v.property(VertexProperty.Cardinality.single, "boundary", Geoshape.polygon(Arrays.asList(new double[][] { { offset - 0.1, offset - 0.1 }, { offset + 0.1, offset - 0.1 }, { offset + 0.1, offset + 0.1 }, { offset - 0.1, offset + 0.1 }, { offset - 0.1, offset - 0.1 } })));
}
Edge e = v.addEdge("knows", getVertex("uid", Math.max(0, i - 1)));
e.property("text", "Vertex " + words[i % words.length]);
e.property("name", words[i % words.length]);
e.property("time", i);
e.property("category", i % numCategories);
e.property("group", i % numGroups);
e.property("location", Geoshape.point(0.0 + offset, 0.0 + offset));
if (i % 2 == 0) {
e.property("boundary", Geoshape.line(Arrays.asList(new double[][] { { offset - 0.1, offset - 0.1 }, { offset + 0.1, offset - 0.1 }, { offset + 0.1, offset + 0.1 }, { offset - 0.1, offset + 0.1 } })));
} else {
e.property("boundary", Geoshape.polygon(Arrays.asList(new double[][] { { offset - 0.1, offset - 0.1 }, { offset + 0.1, offset - 0.1 }, { offset + 0.1, offset + 0.1 }, { offset - 0.1, offset + 0.1 }, { offset - 0.1, offset - 0.1 } })));
}
}
checkIndexingCounts(words, numV, originalNumV, true);
// some indexing backends may guarantee only eventual consistency
for (int retry = 0, status = 1; retry < RETRY_COUNT && status > 0; retry++) {
clopen();
try {
checkIndexingCounts(words, numV, originalNumV, true);
status = 0;
} catch (AssertionError e) {
if (retry >= RETRY_COUNT - 1)
throw e;
Thread.sleep(RETRY_INTERVAL);
}
}
newTx();
int numDelete = 12;
for (int i = numV - numDelete; i < numV; i++) {
getVertex("uid", i).remove();
}
numV -= numDelete;
checkIndexingCounts(words, numV, originalNumV, false);
}
Aggregations