Search in sources :

Example 31 with TitanVertex

use of com.thinkaurelius.titan.core.TitanVertex 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());
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) TitanIndexQuery(com.thinkaurelius.titan.core.TitanIndexQuery) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 32 with TitanVertex

use of com.thinkaurelius.titan.core.TitanVertex 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");
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) Test(org.junit.Test)

Example 33 with TitanVertex

use of com.thinkaurelius.titan.core.TitanVertex 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;
    }
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) TitanVertexProperty(com.thinkaurelius.titan.core.TitanVertexProperty) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) TitanGraphIndex(com.thinkaurelius.titan.core.schema.TitanGraphIndex) Edge(org.apache.tinkerpop.gremlin.structure.Edge) PropertyKey(com.thinkaurelius.titan.core.PropertyKey)

Example 34 with TitanVertex

use of com.thinkaurelius.titan.core.TitanVertex 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();
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) Backend(com.thinkaurelius.titan.diskstorage.Backend) TitanTransaction(com.thinkaurelius.titan.core.TitanTransaction) PropertyKey(com.thinkaurelius.titan.core.PropertyKey)

Example 35 with TitanVertex

use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.

the class TitanIndexTest method testBooleanIndexing.

/**
     * Tests indexing boolean
     */
@Test
public void testBooleanIndexing() {
    PropertyKey name = makeKey("visible", Boolean.class);
    mgmt.buildIndex("booleanIndex", Vertex.class).addKey(name).buildMixedIndex(INDEX);
    finishSchema();
    clopen();
    TitanVertex v1 = graph.addVertex();
    v1.property("visible", true);
    TitanVertex v2 = graph.addVertex();
    v2.property("visible", false);
    assertCount(2, graph.vertices());
    assertEquals(v1, getOnlyVertex(graph.query().has("visible", true)));
    assertEquals(v2, getOnlyVertex(graph.query().has("visible", false)));
    assertEquals(v2, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, true)));
    assertEquals(v1, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, false)));
    //Flush the index
    clopen();
    assertCount(2, graph.vertices());
    assertEquals(v1, getOnlyVertex(graph.query().has("visible", true)));
    assertEquals(v2, getOnlyVertex(graph.query().has("visible", false)));
    assertEquals(v2, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, true)));
    assertEquals(v1, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, false)));
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) Test(org.junit.Test)

Aggregations

TitanVertex (com.thinkaurelius.titan.core.TitanVertex)77 Test (org.junit.Test)63 PropertyKey (com.thinkaurelius.titan.core.PropertyKey)46 EdgeLabel (com.thinkaurelius.titan.core.EdgeLabel)21 TitanEdge (com.thinkaurelius.titan.core.TitanEdge)17 Edge (org.apache.tinkerpop.gremlin.structure.Edge)17 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)14 VertexLabel (com.thinkaurelius.titan.core.VertexLabel)12 TitanGraphIndex (com.thinkaurelius.titan.core.schema.TitanGraphIndex)12 TitanVertexProperty (com.thinkaurelius.titan.core.TitanVertexProperty)10 BaseVertexLabel (com.thinkaurelius.titan.graphdb.types.system.BaseVertexLabel)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 TitanTransaction (com.thinkaurelius.titan.core.TitanTransaction)8 VertexProperty (org.apache.tinkerpop.gremlin.structure.VertexProperty)7 ElementCategory (com.thinkaurelius.titan.graphdb.internal.ElementCategory)4 Category (org.junit.experimental.categories.Category)4 SchemaViolationException (com.thinkaurelius.titan.core.SchemaViolationException)3 VertexList (com.thinkaurelius.titan.core.VertexList)3 RelationTypeIndex (com.thinkaurelius.titan.core.schema.RelationTypeIndex)3 TitanGraphBaseTest (com.thinkaurelius.titan.graphdb.TitanGraphBaseTest)3