Search code examples
titangremlintinkerpoptinkerpop3

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


During my migration from TP2 0.54 -> TP3 titan 1.0 / Tinkerpop 3.01

I'm trying to build gremlin query which make "logical OR" with Predicate Text , between properties on different Vertex indexes

Something like:

------------------- PRE-DEFINED ES INDEXES: ------------------

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'...

------------------- EXPECTED RESULT: -----------

I want to return all vertexes with property "storyContent" match text contains prefix , OR all vertexes with property "userContent" matching its case.
in this case return v1 and v2 , because v3 doesn't match and v4 duplicated so it must be ignored by dedup step

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

or maybe :

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

PS,

I thought use TP3 OR step with dedup , but gremlin throws error ...

Thanks for any help

Vitaly


Solution

  • How about something along those lines:

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

    Edit - as mentioned in the comments, this query won't use any index. It must be split into two separate queries.

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

    With Titan, you might have to import text predicates before:

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

    _.() is TinkerPop2 material and no longer used in TinkerPop3. You now use anonymous traversals as predicates, which sometimes have to start with __. for steps named with reserved keywords in Groovy (for ex. __.in()).