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

The following examples show how to use com.thinkaurelius.titan.core.attribute.Geo. 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: 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 #2
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 #3
Source File: TitanIndexTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
private void testCollection(Cardinality cardinality, String property, Object value1, Object value2) {
    clopen();

    Vertex v1 = graph.addVertex();

    //Adding properties one at a time
    v1.property(property, value1);
    clopen();//Flush the index
    assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices()));

    v1 = getV(graph, v1.id());
    v1.property(property, value2);

    assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices()));
    assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));
    clopen();//Flush the index
    assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices()));
    assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));

    //Remove the properties
    v1 = getV(graph, v1.id());
    v1.properties(property).forEachRemaining(p -> {
        if (p.value().equals(value1)) {
            p.remove();
        }
    });

    assertFalse(graph.query().has(property, value1).vertices().iterator().hasNext());
    assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));
    clopen();//Flush the index
    assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));
    assertFalse(graph.query().has(property, value1).vertices().iterator().hasNext());

    //Re add the properties
    v1 = getV(graph, v1.id());
    v1.property(property, value1);
    assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices()));
    assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));
    clopen();//Flush the index
    assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices()));
    assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));

    //Add a duplicate property
    v1 = getV(graph, v1.id());
    v1.property(property, value1);


    assertEquals(Cardinality.SET.equals(cardinality) ? 2 : 3, Iterators.size(getOnlyVertex(graph.query().has(property, value1)).properties(property)));
    clopen();//Flush the index
    assertEquals(Cardinality.SET.equals(cardinality) ? 2 : 3, Iterators.size(getOnlyVertex(graph.query().has(property, value1)).properties(property)));


    //Add two properties at once to a fresh vertex
    graph.vertices().forEachRemaining(v -> v.remove());
    v1 = graph.addVertex();
    v1.property(property, value1);
    v1.property(property, value2);

    assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices()));
    assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));
    clopen();//Flush the index
    assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices()));
    assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));

    //If this is a geo test then try a within query
    if (value1 instanceof Geoshape) {
        assertEquals(v1, getOnlyElement(graph.query().has(property, Geo.WITHIN, Geoshape.circle(1.0, 1.0, 0.1)).vertices()));
        assertEquals(v1, getOnlyElement(graph.query().has(property, Geo.WITHIN, Geoshape.circle(2.0, 2.0, 0.1)).vertices()));
    }


}
 
Example #4
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));
}