Reputation: 2657
The problem is basically searching inside a multi-level embedded ODocument. Let me explain,
I have three orientDB classes - Feedback, File, and FileContent.
Feedback ODocument has an embedded field reference to File ODocument, and File has an embedded reference to FileContent.
FileContent has a field 'content' that basically has text for the file where I want to search.
Use Case: Write a select query on Feedback class so that it gives me all Feedback ODocuments that have the search keyword.
That is,
If I want to search for the keyword 'progress' in the file content, and fetch all feedbacks that have this keyword, the sql would look like:
select * from Feedback where any() like '%progress%'
But this query doesn't search through file content.
Any help is appreciated.
Here is an example sequence of events to achieve the current state:
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", ...}
Upvotes: 1
Views: 285
Reputation: 25
Use traverse statement.. it will solve your problem.. but you can't get the feedback coz you have to use embedded..
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"));
}
}
this will return File and FileContent class...
Upvotes: 0