use of com.thinkaurelius.titan.core.PropertyKey in project titan by thinkaurelius.
the class TitanIndexTest method testIndexQueryWithScore.
@Test
public void testIndexQueryWithScore() throws InterruptedException {
PropertyKey textKey = mgmt.makePropertyKey("text").dataType(String.class).make();
mgmt.buildIndex("store1", Vertex.class).addKey(textKey).buildMixedIndex(INDEX);
mgmt.commit();
TitanVertex v1 = tx.addVertex();
TitanVertex v2 = tx.addVertex();
TitanVertex v3 = tx.addVertex();
v1.property("text", "Hello Hello Hello Hello Hello Hello Hello Hello");
v2.property("text", "Hello abab abab fsdfsd sfdfsd sdffs fsdsdf fdf fsdfsd aera fsad abab abab fsdfsd sfdf");
v3.property("text", "Hello");
tx.commit();
Thread.sleep(5000);
Set<Double> scores = new HashSet<Double>();
for (TitanIndexQuery.Result<TitanVertex> r : graph.indexQuery("store1", "v.text:(Hello)").vertices()) {
scores.add(r.getScore());
}
Assert.assertEquals(3, scores.size());
}
use of com.thinkaurelius.titan.core.PropertyKey in project titan by thinkaurelius.
the class TitanIndexTest method testIndexing.
private void testIndexing(Cardinality cardinality) {
if (supportsCollections()) {
PropertyKey stringProperty = mgmt.makePropertyKey("name").dataType(String.class).cardinality(cardinality).make();
PropertyKey intProperty = mgmt.makePropertyKey("age").dataType(Integer.class).cardinality(cardinality).make();
PropertyKey longProperty = mgmt.makePropertyKey("long").dataType(Long.class).cardinality(cardinality).make();
PropertyKey uuidProperty = mgmt.makePropertyKey("uuid").dataType(UUID.class).cardinality(cardinality).make();
PropertyKey geoProperty = mgmt.makePropertyKey("geo").dataType(Geoshape.class).cardinality(cardinality).make();
mgmt.buildIndex("collectionIndex", Vertex.class).addKey(stringProperty, getStringMapping()).addKey(intProperty).addKey(longProperty).addKey(uuidProperty).addKey(geoProperty).buildMixedIndex(INDEX);
finishSchema();
testCollection(cardinality, "name", "Totoro", "Hiro");
testCollection(cardinality, "age", 1, 2);
testCollection(cardinality, "long", 1L, 2L);
testCollection(cardinality, "uuid", UUID.randomUUID(), UUID.randomUUID());
testCollection(cardinality, "geo", Geoshape.point(1.0, 1.0), Geoshape.point(2.0, 2.0));
} else {
try {
PropertyKey stringProperty = mgmt.makePropertyKey("name").dataType(String.class).cardinality(cardinality).make();
//This should throw an exception
mgmt.buildIndex("collectionIndex", Vertex.class).addKey(stringProperty, getStringMapping()).buildMixedIndex(INDEX);
Assert.fail("Should have thrown an exception");
} catch (TitanException e) {
}
}
}
use of com.thinkaurelius.titan.core.PropertyKey in project titan by thinkaurelius.
the class TitanIndexTest method testContainsWithMultipleValues.
@Test
public // so we need to make sure that we don't apply AND twice.
void testContainsWithMultipleValues() throws Exception {
PropertyKey name = makeKey("name", String.class);
mgmt.buildIndex("store1", Vertex.class).addKey(name).buildMixedIndex(INDEX);
mgmt.commit();
TitanVertex v1 = tx.addVertex();
v1.property("name", "hercules was here");
tx.commit();
Thread.sleep(2000);
TitanVertex r = Iterables.<TitanVertex>get(graph.query().has("name", Text.CONTAINS, "hercules here").vertices(), 0);
Assert.assertEquals(r.property("name").value(), "hercules was here");
}
use of com.thinkaurelius.titan.core.PropertyKey in project titan by thinkaurelius.
the class TitanIndexTest method setupChainGraph.
private void setupChainGraph(int numV, String[] strs, boolean sameNameMapping) {
clopen(option(INDEX_NAME_MAPPING, INDEX), sameNameMapping);
TitanGraphIndex vindex = getExternalIndex(Vertex.class, INDEX);
TitanGraphIndex eindex = getExternalIndex(Edge.class, INDEX);
TitanGraphIndex pindex = getExternalIndex(TitanVertexProperty.class, INDEX);
PropertyKey name = makeKey("name", String.class);
mgmt.addIndexKey(vindex, name, getStringMapping());
mgmt.addIndexKey(eindex, name, getStringMapping());
mgmt.addIndexKey(pindex, name, getStringMapping(), Parameter.of("mapped-name", "xstr"));
PropertyKey text = makeKey("text", String.class);
mgmt.addIndexKey(vindex, text, getTextMapping(), Parameter.of("mapped-name", "xtext"));
mgmt.addIndexKey(eindex, text, getTextMapping());
mgmt.addIndexKey(pindex, text, getTextMapping());
mgmt.makeEdgeLabel("knows").signature(name).make();
mgmt.makePropertyKey("uid").dataType(String.class).signature(text).make();
finishSchema();
TitanVertex previous = null;
for (int i = 0; i < numV; i++) {
TitanVertex v = graph.addVertex("name", strs[i % strs.length], "text", strs[i % strs.length]);
Edge e = v.addEdge("knows", previous == null ? v : previous, "name", strs[i % strs.length], "text", strs[i % strs.length]);
VertexProperty p = v.property("uid", "v" + i, "name", strs[i % strs.length], "text", strs[i % strs.length]);
previous = v;
}
}
use of com.thinkaurelius.titan.core.PropertyKey in project titan by thinkaurelius.
the class TitanIndexTest method testNestedWrites.
private void testNestedWrites(String initialValue, String updatedValue) throws BackendException {
// This method touches a single vertex with multiple transactions,
// leading to deadlock under BDB and cascading test failures. Check for
// the hasTxIsolation() store feature, which is currently true for BDB
// but false for HBase/Cassandra. This is kind of a hack; a more robust
// approach might implement different methods/assertions depending on
// whether the store is capable of deadlocking or detecting conflicting
// writes and aborting a transaction.
Backend b = null;
try {
b = graph.getConfiguration().getBackend();
if (b.getStoreFeatures().hasTxIsolation()) {
log.info("Skipping " + getClass().getSimpleName() + "." + methodName.getMethodName());
return;
}
} finally {
if (null != b)
b.close();
}
final String propName = "foo";
// Write schema and one vertex
PropertyKey prop = makeKey(propName, String.class);
createExternalVertexIndex(prop, INDEX);
finishSchema();
TitanVertex v = graph.addVertex();
if (null != initialValue)
v.property(VertexProperty.Cardinality.single, propName, initialValue);
graph.tx().commit();
Object id = v.id();
// Open two transactions and modify the same vertex
TitanTransaction vertexDeleter = graph.newTransaction();
TitanTransaction propDeleter = graph.newTransaction();
getV(vertexDeleter, id).remove();
if (null == updatedValue)
getV(propDeleter, id).property(propName).remove();
else
getV(propDeleter, id).property(VertexProperty.Cardinality.single, propName, updatedValue);
vertexDeleter.commit();
propDeleter.commit();
// The vertex must not exist after deletion
graph.tx().rollback();
assertEquals(null, getV(graph, id));
assertEmpty(graph.query().has(propName).vertices());
if (null != updatedValue)
assertEmpty(graph.query().has(propName, updatedValue).vertices());
graph.tx().rollback();
}
Aggregations