如何使用谓词文本在 Titan 1.0 / TP3 3.01 中的顶点索引之间进行逻辑或

How make logic OR between vertex Indexes in Titan 1.0 / TP3 3.01 using predicate Text

在我从 TP2 0.54 -> TP3 titan 1.0 / Tinkerpop 3.01 迁移期间

我正在尝试构建 gremlin 查询,使 "logical OR" 具有 Predicate Text ,在不同 Vertex 索引的属性之间

类似于:

--------------------预定义的 ES 索引:--------------------

tg = TitanFactory.open('../conf/titan-cassandra-es.properties')
tm = tg.openManagement();
g=tg.traversal();

      PropertyKey pNodeType = createPropertyKey(tm, "nodeType", String.class, Cardinality.SINGLE);
      PropertyKey userContent = createPropertyKey(tm, "storyContent", String.class, Cardinality.SINGLE);
      PropertyKey storyContent = createPropertyKey(tm, "userContent", String.class, Cardinality.SINGLE);

            //"storyContent" : is elasticsearch backend index - mixed
            tm.buildIndex(indexName, Vertex.class).addKey(storyContent, Mapping.TEXTSTRING.asParameter()).ib.addKey(pNodeType, Mapping.TEXTSTRING.asParameter()).buildMixedIndex("search");

            //"userContent" : is elasticsearch backend index - mixed
            tm.buildIndex(indexName, Vertex.class).addKey(userContent, Mapping.TEXTSTRING.asParameter()).ib.addKey(pNodeType, Mapping.TEXTSTRING.asParameter()).buildMixedIndex("search");


            v1= g.addVertex()
            v1.property("nodeType","USER")
            v1.property("userContent" , "dccsdsadas")

            v2= g.addVertex()
            v2.property("nodeType","STORY")
            v2.property("storyContent" , "abdsds")

            v3= g.addVertex()
            v3.property("nodeType","STORY")
            v3.property("storyContent" , "xxxx")              

            v4= g.addVertex()
            v4.property("nodeType","STORY")
            v4.property("storyContent" , "abdsds") , etc'...

-------------------- 预期结果:------------

我想 return 所有具有 属性 "storyContent" 的顶点匹配包含前缀的文本,或者具有 属性 "userContent" 匹配其大小写的所有顶点。
在这种情况下 return v1 和 v2 ,因为 v3 不匹配并且 v4 重复所以它必须被 dedup 步骤忽略

 g.V().has("storyContent", textContainsPrefix("ab")) "OR" has("userContent", textContainsPrefix("dc"))

或者也许:

g.V().or(_().has('storyContent', textContainsPrefix("abc")), _().has('userContent', textContainsPrefix("dcc")))

PS,

我想使用 TP3 OR step with dedup ,但是 gremlin 抛出错误...

感谢您的帮助

维塔利

按照这些思路怎么样:

g.V().or(
    has('storyContent', textContainsPrefix("abc")),
    has('userContent', textContainsPrefix("dcc"))
)

编辑 - 如评论中所述,此查询将不使用任何索引。它必须分成两个单独的查询。

参见 TinkerPop v3.0.1 Drop Step documentation and Titan v1.0.0 Ch. 20 - Index Parameters and Full-Text Search documentation

使用 Titan,您可能必须先导入文本谓词:

import static com.thinkaurelius.titan.core.attribute.Text.*

_.() 是 TinkerPop2 material 并且不再用于 TinkerPop3。您现在使用匿名遍历作为谓词,对于在 Groovy 中使用保留关键字命名的步骤,有时必须以 __. 开头(例如 __.in())。