如何使用Tinkerpop API 3在titan 1.0中对合成索引进行不区分大小写的搜索 [英] How to do a case insensitive search in titan 1.0 on composite index with tinkerpop API 3

查看:78
本文介绍了如何使用Tinkerpop API 3在titan 1.0中对合成索引进行不区分大小写的搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have created a composite index on a property in titan 1.0. Now I want to do a case insensitive search on that property.

如下创建综合索引:

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搜索泰坦图.

Below query is being used to search the titan graph with Tinkerpop API 3.

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

但是没有返回结果..

谁能告诉我如何对titan复合索引进行不区分大小写的搜索?还有其他方法可以达到相同目的吗?

Can anyone please tell how to make a case insensitive search on titan composite index? Is there any other way to achieve the same?

推荐答案

如Titan文档中所述,

As described in the Titan documentation, composite indexes are used for exact matches.

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

One option would be to store the property twice, once with the real value and once with a lowercased value. Here are a couple ways you could do that:

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和文本谓词的混合索引,但要注意

Another option would be to use a mixed index with Mapping.TEXT and a text predicate, but be aware of the gotchas involved with 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')

这篇关于如何使用Tinkerpop API 3在titan 1.0中对合成索引进行不区分大小写的搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆