Java根据多个关键字上搜索_Gremlin通过搜索关键字查询跨多个顶点属性的搜索

  • Post author:
  • Post category:java


3个索引无助于有效地回答您的查询 . 最好创建一个覆盖所有3个字段的单个索引(这并不意味着您的查询必须具有所有字段的条件)并发出直接索引查询:

Sample graph:

g = TitanFactory.open(“conf/titan-cassandra-es.properties”)

m = g.getManagementSystem()

user = m.makeVertexLabel(“USER”).make()

email = m.makePropertyKey(“USER_EMAIL”).dataType(String.class).make()

fname = m.makePropertyKey(“USER_FNAME”).dataType(String.class).make()

lname = m.makePropertyKey(“USER_LNAME”).dataType(String.class).make()

m.buildIndex(“users”, Vertex.class).addKey(email).addKey(fname).addKey(lname).indexOnly(user).buildMixedIndex(“search”)

m.commit()

ElementHelper.setProperties(g.addVertexWithLabel(“USER”), “USER_EMAIL”, “foo@bar.com”, “USER_FNAME”, “foo”, “USER_LNAME”, “bar”)

ElementHelper.setProperties(g.addVertexWithLabel(“USER”), “USER_EMAIL”, “foo@xyz.com”, “USER_FNAME”, “foo”, “USER_LNAME”, “bar”)

ElementHelper.setProperties(g.addVertexWithLabel(“USER”), “USER_EMAIL”, “abc@bar.com”, “USER_FNAME”, “foo”, “USER_LNAME”, “xyz”)

ElementHelper.setProperties(g.addVertexWithLabel(“USER”), “USER_EMAIL”, “foo@baz.com”, “USER_FNAME”, “xyz”, “USER_LNAME”, “bar”)

ElementHelper.setProperties(g.addVertexWithLabel(“USER”), “USER_EMAIL”, “xyz@bar.com”, “USER_FNAME”, “xyz”, “USER_LNAME”, “xyz”)

g.commit()

Direct index query:

gremlin> g.indexQuery(“users”, ‘v.”USER_EMAIL”:/.*xyz.*/ v.”USER_FNAME”:/.*xyz.*/ v.”USER_LNAME”:/.*xyz.*/’).vertices()*.getElement()._().map()

==>{USER_FNAME=xyz, USER_LNAME=xyz, USER_EMAIL=xyz@bar.com}

==>{USER_FNAME=xyz, USER_LNAME=bar, USER_EMAIL=foo@baz.com}

==>{USER_FNAME=foo, USER_LNAME=xyz, USER_EMAIL=abc@bar.com}

==>{USER_FNAME=foo, USER_LNAME=bar, USER_EMAIL=foo@xyz.com}

如您所见,我还用顶点标签替换了 ENTITY_TYPE . 标签可以帮助您保持索引尽可能小 . 例如,如果另一种类型的顶点(例如 PROFILE )也使用属性 USER_EMAIL ,则它不会进入索引(如果它是使用 .indexOnly(user) 创建的) .



版权声明:本文为weixin_28808145原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。