【问题标题】:How to do a case insensitive search in titan 1.0 on composite index with tinkerpop API 3如何使用tinkerpop API 3在titan 1.0中对复合索引进行不区分大小写的搜索
【发布时间】:2016-06-21 22:01:26
【问题描述】:

我在 Titan 1.0 中的一个属性上创建了一个复合索引。现在我想对该属性进行不区分大小写的搜索。

正在创建的复合索引如下:

TitanManagement mgmt = graph.openManagement();

TitanManagement.IndexBuilder nameIndexBuilder = mgmt.buildIndex("name_comp_idx", Vertex.class).addKey("name");

titanGraphIndex = nameIndexBuilder.buildCompositeIndex();

顶点:

TitanVertex vertex= graph.addVertex(T.label, "company");
        entity.property("name", "APPLE");

以下查询用于使用 Tinkerpop API 3 搜索泰坦图。

graph.traversal().V().has("name", "apple").toList()

但是没有返回任何结果..

谁能告诉我如何在 Titan 复合索引上进行不区分大小写的搜索?有没有其他方法可以达到同样的效果?

【问题讨论】:

    标签: indexing composite titan


    【解决方案1】:

    如 Titan 文档中所述,composite indexes 用于精确匹配

    一种选择是将属性存储两次,一次使用实际值,一次使用小写值。您可以通过以下几种方式做到这一点:

    mgmt = graph.openManagement()
    // store the property twice, once with the real value, once with a lowercased value
    // for name, we're using different property names
    name = mgmt.makePropertyKey('name').dataType(String.class).cardinality(Cardinality.SINGLE).make()
    nameLower = mgmt.makePropertyKey('nameLower').dataType(String.class).cardinality(Cardinality.SINGLE).make()
    nameLowerIndex = mgmt.buildIndex('nameLowerIndex', Vertex.class).addKey(nameLower).buildCompositeIndex()
    // for title, we're using a list
    title = mgmt.makePropertyKey('title').dataType(String.class).cardinality(Cardinality.LIST).make()
    titleListIndex = mgmt.buildIndex('titleListIndex', Vertex.class).addKey(title).buildCompositeIndex()
    mgmt.commit()
    
    v = graph.addVertex()
    h = 'HERCULES'
    v.property('name', h)
    v.property('nameLower', h.toLowerCase())
    t = 'GOD'
    v.property('title', t)
    v.property('title', t.toLowerCase())
    graph.tx().commit()
    
    g.V(v).valueMap()
    g.V().has('nameLower', 'hercules').values('name')
    // within predicate is defined in org.apache.tinkerpop.gremlin.process.traversal.P
    g.V().has('title', within('god')).values('title').next()
    

    另一种选择是使用带有Mapping.TEXT 和文本谓词的混合索引,但要注意full-text search 所涉及的问题。

    // Full-text search
    mgmt = graph.openManagement()
    name = mgmt.makePropertyKey('name').dataType(String.class).cardinality(Cardinality.SINGLE).make()
    nameIndex = mgmt.buildIndex('nameIndex', Vertex.class).addKey(name).buildMixedIndex('search')
    mgmt.commit()
    
    v = graph.addVertex()
    v.property('name', 'HERCULES')
    graph.tx().commit()
    
    // wait for a moment
    Thread.sleep(n)
    // text predicates are defined in com.thinkaurelius.titan.core.attribute.Text
    // import static com.thinkaurelius.titan.core.attribute.Text.*
    g.V().has('name', textContains('hercules')).values('name')
    

    【讨论】:

      猜你喜欢
      • 2016-06-20
      • 2011-03-23
      • 2013-02-24
      • 1970-01-01
      • 1970-01-01
      • 2018-02-26
      • 2012-12-20
      • 2010-09-12
      • 2021-06-14
      相关资源
      最近更新 更多