【问题标题】:orientdb search by traversing through fields通过字段遍历进行orientdb搜索
【发布时间】:2015-09-07 20:47:58
【问题描述】:

问题基本上是在多级嵌入式 ODocument 中进行搜索。让我解释一下,

我有三个 orientDB 类——Feedback、File 和 FileContent。

Feedback ODocument 具有对 File ODocument 的嵌入式字段引用,而 File 具有对 FileContent 的嵌入式引用。

FileContent 有一个“内容”字段,它基本上包含我要搜索的文件的文本。

用例:在反馈类上编写一个选择查询,以便它为我提供所有具有搜索关键字的反馈 ODocument。
也就是说,
如果我想在文件内容中搜索关键字'progress',并获取所有包含此关键字的反馈,sql 将如下所示:

select * from Feedback where any() like '%progress%'

但此查询不会搜索文件内容。
任何帮助表示赞赏。

以下是实现当前状态的事件序列示例:

orientdb {db=mydb}> create class Feedback;
orientdb {db=mydb}> create class File;
orientdb {db=mydb}> create class FileContent;
orientdb {db=mydb}> insert into FileContent (a,b) values ('Lebron James','is the King.')
orientdb {db=mydb}> select from FileContent

----+-----+------------+------------
#   |@RID |a           |b
----+-----+------------+------------
0   |#29:0|Lebron James|is the King.
----+-----+------------+------------

orientdb {db=mydb}> insert into File (c,d) values (#29:0, 'Steph Curry too!');
orientdb {db=mydb}> select from File

----+-----+-----+----------------
#   |@RID |c    |d
----+-----+-----+----------------
0   |#27:0|#29:0|Steph Curry too!
----+-----+-----+----------------

orientdb {db=mydb}> insert into Feedback (e,f) values (#27:0, 'The MVP is here.');
orientdb {db=mydb}> select from Feedback

----+-----+-----+----------------
#   |@RID |e    |f
----+-----+-----+----------------
0   |#28:0|#27:0|The MVP is here.
----+-----+-----+----------------

orientdb {db=mydb}> select from File where any() like '%Lebron%';

----+-----+-----+----------------
#   |@RID |c    |d
----+-----+-----+----------------
0   |#27:0|#29:0|Steph Curry too!
----+-----+-----+----------------

1 item(s) found. Query executed in 0.001 sec(s).
orientdb {db=mydb}> select from Feedback where any() like '%Lebron%';

0 item(s) found. Query executed in 0.001 sec(s).

// I want the last query to return the Feedback row. Is it possible?
// Also, I am not declaring the property as embedded here because then I have to do {"@type":"d", ...}

【问题讨论】:

  • 您能否提供一系列命令来实现您当前的状态?我的意思是,你是如何嵌入字段的。
  • @vitorenesduarte 我刚刚发布了这个例子。这与我使用 Document API 所做的很接近。
  • @vitorenesduarte 有帮助吗?
  • 您没有嵌入记录。嵌入式文档不拥有记录 ID。我相信,如果你真正嵌入它们,你会实现你想要的
  • @vitorenesduarte 那么为什么在一级间接搜索(我的示例中的倒数第二个查询)有效?

标签: database select orientdb


【解决方案1】:

使用 traverse 语句..它会解决您的问题..但您无法获得反馈,因为您必须使用嵌入式..

List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("TRAVERSE * FROM File where any() like '%Lebron%'"));

if (result != null && result.size() > 0) {
    for (int i = 0; i < result.size(); i++) {
      System.out.println(result.get(i).field("rid"));
    }
}

这将返回 File 和 FileContent 类...

【讨论】:

    猜你喜欢
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多