【问题标题】:OrientDB, Find Index Insertion pointOrientDB,查找索引插入点
【发布时间】:2015-12-20 10:37:37
【问题描述】:

我有一个带有“日期”属性的“账单”顶点,并在账单日期上创建了一个自动 SB 树不是唯一索引,以便更快地搜索,现在我希望每张插入的账单都与下一张账单有边缘并创建一个链接节点结构,

到目前为止我得到的解决方案:

1- 使用 gremlin 计算插入账单日期与其他账单日期之间的最小差异以获得最接近的账单,但它需要我扫描所有账单并且没有使用索引

2-我可以得到索引的键并使用Collections.binarySearch()得到插入点的索引,从而得到相邻的账单,

但我想知道是否有其他更好的解决方案来链接账单,如何使用 SQL 在 OrientDB 索引中找到插入点,有什么想法吗?

【问题讨论】:

    标签: orientdb gremlin orientdb-2.1


    【解决方案1】:

    我用两个类的简单数据库尝试了您的示例:

    • Bill(扩展 V),属性 billDate 作为日期时间;
    • nextBill(扩展 E)。

    用这个查询

    create vertex Bill set billDate=sysdate(), in_nextBill=(select @rid from Bill where billDate in (select max(billDate) from Bill))
    

    您可以同时创建账单和之前提到的边。

    已编辑

    我创建了一个 Javascript 函数,它删除两条记录之间的边缘并在前两条记录之间插入一条新记录(具有相对边缘)。 该函数接受三个输入参数: * 日期1datetime format; * date2datetime format; * newBillDatedatetime format 是您要在前两个之间插入的新账单日期;

    var g=orient.getGraph();
    var d1=g.command('sql','select from Bill where billDate in "'+date1+'"');
    var d2=g.command('sql','select from Bill where billDate in "'+date2+'"');
    var startDate=d1[0];
    var endDate=d2[0];
    if(endDate.getRecord().field("billDate").getTime()<startDate.getRecord().field("billDate").getTime()){
      var temp=endDate;
      endDate=startDate;
      startDate=temp;
    }
    var selectEdge=g.command('sql','select from nextBill where in='+endDate.getId()+' and out='+startDate.getId());
    g.command('sql','delete edge '+selectEdge[0].getId());
    var newIns=g.command('sql','create vertex Bill set billDate="'+newBillDate+'"');
    g.commit();
    g.command('sql','create edge nextBill from '+startDate.getRecord().getIdentity()+' to '+newIns.getRecord().getIdentity());
    g.command('sql','create edge nextBill from '+newIns.getRecord().getIdentity()+' to '+endDate.getRecord().getIdentity());
    

    【讨论】:

    • 感谢@LucaS 的回答,但是如果我想在两张账单之间插入新账单,假设今天是星期二,新账单将没有sysdate(),而是有 13 个:周日下午 00 点
    • 您好,您要在 2 个预定义日期之间插入新账单吗?
    • 是的,这正是我想要的,问题是搜索这一点的时间随着数据库中账单的增加而增加,我知道这将涉及更改以前、当前和下一个账单之间的边缘,但这一旦我得到正确的插入点应该很容易
    • 嗨,我正在使用 javascript 函数编辑答案,该函数删除两个给定日期之间的边缘并插入新记录“Bill”,并在新记录和先前记录之间创建新的两条边缘.
    • 您好,您有机会试用该功能吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-13
    • 2015-05-26
    • 2010-09-27
    • 1970-01-01
    • 2016-05-13
    • 2013-05-15
    • 1970-01-01
    相关资源
    最近更新 更多