com.thinkaurelius.titan.core.attribute.Text Java Examples

The following examples show how to use com.thinkaurelius.titan.core.attribute.Text. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TitanIndexTest.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Test
// this tests a case when there as AND with a single CONTAINS condition inside AND(name:(was here))
// which (in case of Solr) spans multiple conditions such as AND(AND(name:was, name:here))
// so we need to make sure that we don't apply AND twice.
public 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");
}
 
Example #2
Source File: ElasticSearchConfigTest.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
private void simpleWriteAndQuery(IndexProvider idx) throws BackendException, InterruptedException {

        final Duration maxWrite = Duration.ofMillis(2000L);
        final String storeName = "jvmlocal_test_store";
        final KeyInformation.IndexRetriever indexRetriever = IndexProviderTest.getIndexRetriever(IndexProviderTest.getMapping(idx.getFeatures()));

        BaseTransactionConfig txConfig = StandardBaseTransactionConfig.of(TimestampProviders.MILLI);
        IndexTransaction itx = new IndexTransaction(idx, indexRetriever, txConfig, maxWrite);
        assertEquals(0, itx.query(new IndexQuery(storeName, PredicateCondition.of(IndexProviderTest.NAME, Text.PREFIX, "ali"))).size());
        itx.add(storeName, "doc", IndexProviderTest.NAME, "alice", false);
        itx.commit();
        Thread.sleep(1500L); // Slightly longer than default 1s index.refresh_interval
        itx = new IndexTransaction(idx, indexRetriever, txConfig, maxWrite);
        assertEquals(0, itx.query(new IndexQuery(storeName, PredicateCondition.of(IndexProviderTest.NAME, Text.PREFIX, "zed"))).size());
        assertEquals(1, itx.query(new IndexQuery(storeName, PredicateCondition.of(IndexProviderTest.NAME, Text.PREFIX, "ali"))).size());
        itx.rollback();
    }
 
Example #3
Source File: ProjectionQueryExpression.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
public Pipe asPipe() {
    //todo: encapsulate all of this path logic including path sep escaping and normalizing
    final int sepIdx = getField().indexOf(QueryFactory.PATH_SEP_TOKEN);
    final String edgeToken = getField().substring(0, sepIdx);
    GremlinPipeline pipeline = new GremlinPipeline();

    Relation relation = resourceDefinition.getRelations().get(fieldSegments[0]);
    if (relation != null) {
        pipeline = pipeline.outE();
        pipeline.add(relation.asPipe()).inV();
    } else {
        if (resourceDefinition.getProjections().get(fieldSegments[0]) != null) {
            return super.asPipe();
        } else {
            //todo: default Relation implementation
            pipeline = pipeline.outE().has("label", Text.REGEX, String.format(".*\\.%s", edgeToken)).inV();
        }
    }
    //todo: set resource definition from relation on underlying expression where appropriate
    String childFieldName = getField().substring(sepIdx + QueryFactory.PATH_SEP_TOKEN.length());
    underlyingExpression.setField(childFieldName);

    Pipe childPipe;
    if (childFieldName.contains(QueryFactory.PATH_SEP_TOKEN)) {
        childPipe = new ProjectionQueryExpression(underlyingExpression, resourceDefinition).asPipe();
    } else {
        childPipe = underlyingExpression.asPipe();
    }
    pipeline.add(childPipe);

    return negate ? new FilterFunctionPipe(new ExcludePipeFunction(pipeline)) : pipeline;
}
 
Example #4
Source File: AtlasTermQuery.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
protected Pipe getQueryPipe() {
    GremlinPipeline p;
    if (termPath.getTaxonomyName().equals("*")) {
        p = new GremlinPipeline().has("Taxonomy.name").out();
    } else {
        p = new GremlinPipeline().has("Taxonomy.name", termPath.getTaxonomyName()).out().
                has(Constants.ENTITY_TYPE_PROPERTY_KEY, Text.PREFIX, termPath.getFullyQualifiedName());
    }
    return p;
}
 
Example #5
Source File: NativeTitan1GraphQuery.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private Text getGremlinPredicate(MatchingOperator op) {
    switch (op) {
        case CONTAINS:
            return Text.CONTAINS;
        case PREFIX:
            return Text.PREFIX;
        case SUFFIX:
            return Text.CONTAINS_REGEX;
        case REGEX:
            return Text.REGEX;
        default:
            throw new RuntimeException("Unsupported matching operator:" + op);
    }
}
 
Example #6
Source File: NativeTitan0GraphQuery.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private Text getGremlinPredicate(MatchingOperator op) {
    switch (op) {
        case CONTAINS:
            return Text.CONTAINS;
        case PREFIX:
            return Text.PREFIX;
        case SUFFIX:
            return Text.CONTAINS_REGEX;
        case REGEX:
            return Text.REGEX;
        default:
            throw new RuntimeException("Unsupported matching operator:" + op);
    }
}
 
Example #7
Source File: Solr5Index.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
public boolean supports(KeyInformation information, TitanPredicate titanPredicate) {
    Class<?> dataType = information.getDataType();
    Mapping mapping = getMapping(information);
    if (mapping!= DEFAULT && !AttributeUtil.isString(dataType)) return false;

    if (Number.class.isAssignableFrom(dataType)) {
        return titanPredicate instanceof Cmp;
    } else if (dataType == Geoshape.class) {
        return titanPredicate == Geo.WITHIN;
    } else if (AttributeUtil.isString(dataType)) {
        switch(mapping) {
            case DEFAULT:
            case TEXT:
                return titanPredicate == Text.CONTAINS || titanPredicate == Text.CONTAINS_PREFIX || titanPredicate == Text.CONTAINS_REGEX;
            case STRING:
                return titanPredicate == EQUAL || titanPredicate== NOT_EQUAL || titanPredicate==Text.REGEX || titanPredicate==Text.PREFIX;
            //                case TEXTSTRING:
            //                    return (titanPredicate instanceof Text) || titanPredicate == Cmp.EQUAL || titanPredicate==Cmp.NOT_EQUAL;
        }
    } else if (dataType == Date.class) {
        if (titanPredicate instanceof Cmp) return true;
    } else if (dataType == Boolean.class) {
        return titanPredicate == EQUAL || titanPredicate == NOT_EQUAL;
    } else if (dataType == UUID.class) {
        return titanPredicate == EQUAL || titanPredicate== NOT_EQUAL;
    }
    return false;
}
 
Example #8
Source File: BlurIndex.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
@Override
public boolean supports(Class<?> dataType, Relation relation) {
  if (Number.class.isAssignableFrom(dataType)) {
    if (relation instanceof Cmp) {
      return true;
    }
  } else if (dataType == Geoshape.class) {
    return relation == Geo.INTERSECT;
  } else if (dataType == String.class) {
    return relation == Text.CONTAINS;
  }
  return false;
}
 
Example #9
Source File: TitanIndexTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Test
public void testCompositeAndMixedIndexing() {
    PropertyKey name = makeKey("name", String.class);
    PropertyKey weight = makeKey("weight", Double.class);
    PropertyKey text = makeKey("text", String.class);
    PropertyKey flag = makeKey("flag", Boolean.class);

    TitanGraphIndex composite = mgmt.buildIndex("composite", Vertex.class).addKey(name).addKey(weight).buildCompositeIndex();
    TitanGraphIndex mixed = mgmt.buildIndex("mixed", Vertex.class).addKey(weight)
            .addKey(text, getTextMapping()).buildMixedIndex(INDEX);
    mixed.name();
    composite.name();
    finishSchema();

    final int numV = 100;
    String[] strs = {"houseboat", "humanoid", "differential", "extraordinary"};
    String[] strs2 = new String[strs.length];
    for (int i = 0; i < strs.length; i++) strs2[i] = strs[i] + " " + strs[i];
    final int modulo = 5;
    final int divisor = modulo * strs.length;

    for (int i = 0; i < numV; i++) {
        TitanVertex v = tx.addVertex();
        v.property("name", strs[i % strs.length]);
        v.property("text", strs[i % strs.length]);
        v.property("weight", (i % modulo) + 0.5);
        v.property("flag", true);
    }

    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[0]), ElementCategory.VERTEX,
            numV / strs.length, new boolean[]{false, true});
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[0]), ElementCategory.VERTEX,
            numV / strs.length, new boolean[]{true, true}, mixed.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[0]).has("flag"), ElementCategory.VERTEX,
            numV / strs.length, new boolean[]{false, true}, mixed.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[0]).has("weight", Cmp.EQUAL, 1.5), ElementCategory.VERTEX,
            numV / divisor, new boolean[]{true, true}, composite.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[0]).has("weight", Cmp.EQUAL, 1.5).has("flag"), ElementCategory.VERTEX,
            numV / divisor, new boolean[]{false, true}, composite.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[2]).has("weight", Cmp.EQUAL, 2.5), ElementCategory.VERTEX,
            numV / divisor, new boolean[]{true, true}, mixed.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[2]).has("weight", Cmp.EQUAL, 2.5).has("flag"), ElementCategory.VERTEX,
            numV / divisor, new boolean[]{false, true}, mixed.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[3]).has("name", Cmp.EQUAL, strs[3]).has("weight", Cmp.EQUAL, 3.5), ElementCategory.VERTEX,
            numV / divisor, new boolean[]{true, true}, mixed.name(), composite.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[3]).has("name", Cmp.EQUAL, strs[3]).has("weight", Cmp.EQUAL, 3.5).has("flag"), ElementCategory.VERTEX,
            numV / divisor, new boolean[]{false, true}, mixed.name(), composite.name());

    clopen();

    //Same queries as above
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[0]), ElementCategory.VERTEX,
            numV / strs.length, new boolean[]{false, true});
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[0]), ElementCategory.VERTEX,
            numV / strs.length, new boolean[]{true, true}, mixed.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[0]).has("flag"), ElementCategory.VERTEX,
            numV / strs.length, new boolean[]{false, true}, mixed.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[0]).has("weight", Cmp.EQUAL, 1.5), ElementCategory.VERTEX,
            numV / divisor, new boolean[]{true, true}, composite.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[0]).has("weight", Cmp.EQUAL, 1.5).has("flag"), ElementCategory.VERTEX,
            numV / divisor, new boolean[]{false, true}, composite.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[2]).has("weight", Cmp.EQUAL, 2.5), ElementCategory.VERTEX,
            numV / divisor, new boolean[]{true, true}, mixed.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[2]).has("weight", Cmp.EQUAL, 2.5).has("flag"), ElementCategory.VERTEX,
            numV / divisor, new boolean[]{false, true}, mixed.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[3]).has("name", Cmp.EQUAL, strs[3]).has("weight", Cmp.EQUAL, 3.5), ElementCategory.VERTEX,
            numV / divisor, new boolean[]{true, true}, mixed.name(), composite.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[3]).has("name", Cmp.EQUAL, strs[3]).has("weight", Cmp.EQUAL, 3.5).has("flag"), ElementCategory.VERTEX,
            numV / divisor, new boolean[]{false, true}, mixed.name(), composite.name());

}
 
Example #10
Source File: TitanIndexTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Test
public void testDualMapping() {
    if (!indexFeatures.supportsStringMapping(Mapping.TEXTSTRING)) return;

    PropertyKey name = makeKey("name", String.class);
    TitanGraphIndex mixed = mgmt.buildIndex("mixed", Vertex.class).addKey(name, Mapping.TEXTSTRING.asParameter()).buildMixedIndex(INDEX);
    mixed.name();
    finishSchema();


    tx.addVertex("name", "Long John Don");
    tx.addVertex("name", "Long Little Lewis");
    tx.addVertex("name", "Middle Sister Mabel");

    clopen();
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, "Long John Don"), ElementCategory.VERTEX,
            1, new boolean[]{true, true}, "mixed");
    evaluateQuery(tx.query().has("name", Text.CONTAINS, "Long"), ElementCategory.VERTEX,
            2, new boolean[]{true, true}, "mixed");
    evaluateQuery(tx.query().has("name", Text.CONTAINS, "Long Don"), ElementCategory.VERTEX,
            1, new boolean[]{true, true}, "mixed");
    evaluateQuery(tx.query().has("name", Text.CONTAINS_PREFIX, "Lon"), ElementCategory.VERTEX,
            2, new boolean[]{true, true}, "mixed");
    evaluateQuery(tx.query().has("name", Text.CONTAINS_REGEX, "Lit*le"), ElementCategory.VERTEX,
            1, new boolean[]{true, true}, "mixed");
    evaluateQuery(tx.query().has("name", Text.REGEX, "Long.*"), ElementCategory.VERTEX,
            2, new boolean[]{true, true}, "mixed");
    evaluateQuery(tx.query().has("name", Text.PREFIX, "Middle"), ElementCategory.VERTEX,
            1, new boolean[]{true, true}, "mixed");

    for (Vertex u : tx.getVertices()) {
        String n = u.<String>value("name");
        if (n.endsWith("Don")) {
            u.remove();
        } else if (n.endsWith("Lewis")) {
            u.property(VertexProperty.Cardinality.single, "name", "Big Brother Bob");
        } else if (n.endsWith("Mabel")) {
            u.property("name").remove();
        }
    }

    clopen();

    evaluateQuery(tx.query().has("name", Text.CONTAINS, "Long"), ElementCategory.VERTEX,
            0, new boolean[]{true, true}, "mixed");
    evaluateQuery(tx.query().has("name", Text.CONTAINS, "Big"), ElementCategory.VERTEX,
            1, new boolean[]{true, true}, "mixed");
    evaluateQuery(tx.query().has("name", Text.PREFIX, "Big"), ElementCategory.VERTEX,
            1, new boolean[]{true, true}, "mixed");
    evaluateQuery(tx.query().has("name", Text.PREFIX, "Middle"), ElementCategory.VERTEX,
            0, new boolean[]{true, true}, "mixed");

}
 
Example #11
Source File: TitanIndexTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Category({BrittleTests.class})
    @Test
    public void testIndexReplay() throws Exception {
        final TimestampProvider times = graph.getConfiguration().getTimestampProvider();
        final Instant startTime = times.getTime();
        clopen(option(SYSTEM_LOG_TRANSACTIONS), true
                , option(KCVSLog.LOG_READ_LAG_TIME, TRANSACTION_LOG), Duration.ofMillis(50)
                , option(LOG_READ_INTERVAL, TRANSACTION_LOG), Duration.ofMillis(250)
                , option(MAX_COMMIT_TIME), Duration.ofSeconds(1)
                , option(STORAGE_WRITE_WAITTIME), Duration.ofMillis(300)
                , option(TestMockIndexProvider.INDEX_BACKEND_PROXY, INDEX), readConfig.get(INDEX_BACKEND, INDEX)
                , option(INDEX_BACKEND, INDEX), TestMockIndexProvider.class.getName()
                , option(TestMockIndexProvider.INDEX_MOCK_FAILADD, INDEX), true
        );

        PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
        PropertyKey age = mgmt.makePropertyKey("age").dataType(Integer.class).make();
        mgmt.buildIndex("mi", Vertex.class).addKey(name, getTextMapping()).addKey(age).buildMixedIndex(INDEX);
        finishSchema();
        Vertex vs[] = new TitanVertex[4];

        vs[0] = tx.addVertex("name", "Big Boy Bobson", "age", 55);
        newTx();
        vs[1] = tx.addVertex("name", "Long Little Lewis", "age", 35);
        vs[2] = tx.addVertex("name", "Tall Long Tiger", "age", 75);
        vs[3] = tx.addVertex("name", "Long John Don", "age", 15);
        newTx();
        vs[2] = getV(tx, vs[2]);
        vs[2].remove();
        vs[3] = getV(tx, vs[3]);
        vs[3].property(VertexProperty.Cardinality.single, "name", "Bad Boy Badsy");
        vs[3].property("age").remove();
        newTx();
        vs[0] = getV(tx, vs[0]);
        vs[0].property(VertexProperty.Cardinality.single, "age", 66);
        newTx();

        clopen();
        //Just to make sure nothing has been persisted to index
        evaluateQuery(tx.query().has("name", Text.CONTAINS, "boy"),
                ElementCategory.VERTEX, 0, new boolean[]{true, true}, "mi");
        /*
        Transaction Recovery
         */
        TransactionRecovery recovery = TitanFactory.startTransactionRecovery(graph, startTime);
        //wait
        Thread.sleep(12000L);

        recovery.shutdown();
        long[] recoveryStats = ((StandardTransactionLogProcessor) recovery).getStatistics();

        clopen();

        evaluateQuery(tx.query().has("name", Text.CONTAINS, "boy"),
                ElementCategory.VERTEX, 2, new boolean[]{true, true}, "mi");
        evaluateQuery(tx.query().has("name", Text.CONTAINS, "long"),
                ElementCategory.VERTEX, 1, new boolean[]{true, true}, "mi");
//        TitanVertex v = Iterables.getOnlyElement(tx.query().has("name",Text.CONTAINS,"long").vertices());
//        System.out.println(v.getProperty("age"));
        evaluateQuery(tx.query().has("name", Text.CONTAINS, "long").interval("age", 30, 40),
                ElementCategory.VERTEX, 1, new boolean[]{true, true}, "mi");
        evaluateQuery(tx.query().has("age", 75),
                ElementCategory.VERTEX, 0, new boolean[]{true, true}, "mi");
        evaluateQuery(tx.query().has("name", Text.CONTAINS, "boy").interval("age", 60, 70),
                ElementCategory.VERTEX, 1, new boolean[]{true, true}, "mi");
        evaluateQuery(tx.query().interval("age", 0, 100),
                ElementCategory.VERTEX, 2, new boolean[]{true, true}, "mi");


        assertEquals(1, recoveryStats[0]); //schema transaction was successful
        assertEquals(4, recoveryStats[1]); //all 4 index transaction had provoked errors in the indexing backend
    }
 
Example #12
Source File: TitanIndexTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Test
public void testVertexTTLWithMixedIndices() throws Exception {
    if (!features.hasCellTTL() || !indexFeatures.supportsDocumentTTL()) {
        return;
    }

    PropertyKey name = makeKey("name", String.class);
    PropertyKey time = makeKey("time", Long.class);
    PropertyKey text = makeKey("text", String.class);

    VertexLabel event = mgmt.makeVertexLabel("event").setStatic().make();
    final int eventTTLSeconds = (int) TestGraphConfigs.getTTL(TimeUnit.SECONDS);
    mgmt.setTTL(event, Duration.ofSeconds(eventTTLSeconds));

    mgmt.buildIndex("index1", Vertex.class).
            addKey(name, getStringMapping()).addKey(time).buildMixedIndex(INDEX);
    mgmt.buildIndex("index2", Vertex.class).indexOnly(event).
            addKey(text, getTextMapping()).buildMixedIndex(INDEX);

    assertEquals(Duration.ZERO, mgmt.getTTL(name));
    assertEquals(Duration.ZERO, mgmt.getTTL(time));
    assertEquals(Duration.ofSeconds(eventTTLSeconds), mgmt.getTTL(event));
    finishSchema();

    TitanVertex v1 = tx.addVertex("event");
    v1.property(VertexProperty.Cardinality.single, "name", "first event");
    v1.property(VertexProperty.Cardinality.single, "text", "this text will help to identify the first event");
    long time1 = System.currentTimeMillis();
    v1.property(VertexProperty.Cardinality.single, "time", time1);
    TitanVertex v2 = tx.addVertex("event");
    v2.property(VertexProperty.Cardinality.single, "name", "second event");
    v2.property(VertexProperty.Cardinality.single, "text", "this text won't match");
    long time2 = time1 + 1;
    v2.property(VertexProperty.Cardinality.single, "time", time2);

    evaluateQuery(tx.query().has("name", "first event").orderBy("time", decr),
            ElementCategory.VERTEX, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC, "index1");
    evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "event"),
            ElementCategory.VERTEX, 1, new boolean[]{true, true}, "index2");

    clopen();

    Object v1Id = v1.id();
    Object v2Id = v2.id();

    evaluateQuery(tx.query().has("name", "first event").orderBy("time", decr),
            ElementCategory.VERTEX, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC, "index1");
    evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "event"),
            ElementCategory.VERTEX, 1, new boolean[]{true, true}, "index2");

    v1 = getV(tx, v1Id);
    v2 = getV(tx, v1Id);
    assertNotNull(v1);
    assertNotNull(v2);

    Thread.sleep(TimeUnit.MILLISECONDS.convert((long) Math.ceil(eventTTLSeconds * 1.25), TimeUnit.SECONDS));

    clopen();

    Thread.sleep(TimeUnit.MILLISECONDS.convert((long) Math.ceil(eventTTLSeconds * 1.25), TimeUnit.SECONDS));

    evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "event"),
            ElementCategory.VERTEX, 0, new boolean[]{true, true}, "index2");
    evaluateQuery(tx.query().has("name", "first event").orderBy("time", decr),
            ElementCategory.VERTEX, 0, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC, "index1");


    v1 = getV(tx, v1Id);
    v2 = getV(tx, v2Id);
    assertNull(v1);
    assertNull(v2);
}
 
Example #13
Source File: TitanIndexTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Test
public void testEdgeTTLWithMixedIndices() throws Exception {
    if (!features.hasCellTTL() || !indexFeatures.supportsDocumentTTL()) {
        return;
    }

    PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
    PropertyKey text = mgmt.makePropertyKey("text").dataType(String.class).make();
    PropertyKey time = makeKey("time", Long.class);

    EdgeLabel label = mgmt.makeEdgeLabel("likes").make();
    final int likesTTLSeconds = (int) TestGraphConfigs.getTTL(TimeUnit.SECONDS);
    mgmt.setTTL(label, Duration.ofSeconds(likesTTLSeconds));

    mgmt.buildIndex("index1", Edge.class).
            addKey(name, getStringMapping()).addKey(time).buildMixedIndex(INDEX);
    mgmt.buildIndex("index2", Edge.class).indexOnly(label).
            addKey(text, getTextMapping()).buildMixedIndex(INDEX);

    assertEquals(Duration.ZERO, mgmt.getTTL(name));
    assertEquals(Duration.ofSeconds(likesTTLSeconds), mgmt.getTTL(label));
    finishSchema();

    TitanVertex v1 = tx.addVertex(), v2 = tx.addVertex(), v3 = tx.addVertex();

    Edge e1 = v1.addEdge("likes", v2, "name", "v1 likes v2", "text", "this will help to identify the edge");
    long time1 = System.currentTimeMillis();
    e1.property("time", time1);
    Edge e2 = v2.addEdge("likes", v3, "name", "v2 likes v3", "text", "this won't match anything");
    long time2 = time1 + 1;
    e2.property("time", time2);

    tx.commit();

    clopen();
    Object e1Id = e1.id();
    Object e2Id = e2.id();

    evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "likes"),
            ElementCategory.EDGE, 1, new boolean[]{true, true}, "index2");
    evaluateQuery(tx.query().has("name", "v2 likes v3").orderBy("time", decr),
            ElementCategory.EDGE, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC, "index1");
    v1 = getV(tx, v1.id());
    v2 = getV(tx, v2.id());
    v3 = getV(tx, v3.id());
    e1 = getE(tx, e1Id);
    e2 = getE(tx, e1Id);
    assertNotNull(v1);
    assertNotNull(v2);
    assertNotNull(v3);
    assertNotNull(e1);
    assertNotNull(e2);
    assertNotEmpty(v1.query().direction(Direction.OUT).edges());
    assertNotEmpty(v2.query().direction(Direction.OUT).edges());


    Thread.sleep(TimeUnit.MILLISECONDS.convert((long) Math.ceil(likesTTLSeconds * 1.25), TimeUnit.SECONDS));
    clopen();

    // ...indexes have expired
    evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "likes"),
            ElementCategory.EDGE, 0, new boolean[]{true, true}, "index2");
    evaluateQuery(tx.query().has("name", "v2 likes v3").orderBy("time", decr),
            ElementCategory.EDGE, 0, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC, "index1");

    v1 = getV(tx, v1.id());
    v2 = getV(tx, v2.id());
    v3 = getV(tx, v3.id());
    e1 = getE(tx, e1Id);
    e2 = getE(tx, e1Id);
    assertNotNull(v1);
    assertNotNull(v2);
    assertNotNull(v3);
    // edges have expired from the graph...
    assertNull(e1);
    assertNull(e2);
    assertEmpty(v1.query().direction(Direction.OUT).edges());
    assertEmpty(v2.query().direction(Direction.OUT).edges());
}
 
Example #14
Source File: SolrIndexTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Test
public void testSupport() {
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE)));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.TEXT))));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.STRING))));
    assertFalse(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.TEXTSTRING))));

    assertTrue(index.supports(of(Double.class, Cardinality.SINGLE)));
    assertFalse(index.supports(of(Double.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.TEXT))));

    assertTrue(index.supports(of(Long.class, Cardinality.SINGLE)));
    assertTrue(index.supports(of(Long.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.DEFAULT))));
    assertTrue(index.supports(of(Integer.class, Cardinality.SINGLE)));
    assertTrue(index.supports(of(Short.class, Cardinality.SINGLE)));
    assertTrue(index.supports(of(Byte.class, Cardinality.SINGLE)));
    assertTrue(index.supports(of(Float.class, Cardinality.SINGLE)));
    assertTrue(index.supports(of(Geoshape.class, Cardinality.SINGLE)));
    assertFalse(index.supports(of(Object.class, Cardinality.SINGLE)));
    assertFalse(index.supports(of(Exception.class, Cardinality.SINGLE)));

    assertTrue(index.supports(of(String.class, Cardinality.SINGLE), Text.CONTAINS));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.DEFAULT)), Text.CONTAINS_PREFIX));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.TEXT)), Text.CONTAINS_REGEX));
    assertFalse(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.TEXTSTRING)), Text.REGEX));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.TEXT)), Text.CONTAINS));
    assertFalse(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.DEFAULT)), Text.PREFIX));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.STRING)), Text.PREFIX));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.STRING)), Text.REGEX));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.STRING)), Cmp.EQUAL));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.STRING)), Cmp.NOT_EQUAL));
    assertFalse(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.TEXTSTRING)), Cmp.NOT_EQUAL));

    assertTrue(index.supports(of(Double.class, Cardinality.SINGLE), Cmp.EQUAL));
    assertTrue(index.supports(of(Double.class, Cardinality.SINGLE), Cmp.GREATER_THAN_EQUAL));
    assertTrue(index.supports(of(Double.class, Cardinality.SINGLE), Cmp.LESS_THAN));
    assertTrue(index.supports(of(Double.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.DEFAULT)), Cmp.LESS_THAN));
    assertFalse(index.supports(of(Double.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.TEXT)), Cmp.LESS_THAN));
    assertTrue(index.supports(of(Geoshape.class, Cardinality.SINGLE), Geo.WITHIN));

    assertFalse(index.supports(of(Double.class, Cardinality.SINGLE), Geo.INTERSECT));
    assertFalse(index.supports(of(Long.class, Cardinality.SINGLE), Text.CONTAINS));
    assertFalse(index.supports(of(Geoshape.class, Cardinality.SINGLE), Geo.DISJOINT));

    assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.EQUAL));
    assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.LESS_THAN_EQUAL));
    assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.LESS_THAN));
    assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.GREATER_THAN));
    assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.GREATER_THAN_EQUAL));
    assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.NOT_EQUAL));

    assertTrue(index.supports(of(Boolean.class, Cardinality.SINGLE), Cmp.EQUAL));
    assertTrue(index.supports(of(Boolean.class, Cardinality.SINGLE), Cmp.NOT_EQUAL));

    assertTrue(index.supports(of(UUID.class, Cardinality.SINGLE), Cmp.EQUAL));
    assertTrue(index.supports(of(UUID.class, Cardinality.SINGLE), Cmp.NOT_EQUAL));
}