Reccardo, I think we can optimize this query further like this:
SELECT begin, end, text FROM Chunk WHERE (begin <11 AND end > 6) ORDER BY begin If we have four chunks like 1. 0, 5, "Hello" 2. 5, 10, " Worl" 3. 10, 12, "d " 4. 12, 14, "!!" Above query will return 5, 10, " Worl" 10, 12, "d " as "begin < 11 and end > 6" filters only above records. This where condition will be applicable for all your scenarios. So I think SQL query would be better than or equally efficient to the graph traversal in this case. Hope this helps. Regards, Ameer On Monday, 17 February 2014 13:49:20 UTC+5:30, Riccardo Tasso wrote: > > Hi all, > I have to represent a domain with OrientDB and I'm thinking about two > ways. The domain is as follows: > > - a very big text is fragmented in Chunks of equal size (let's say 5 > characters for each Chunk) > - Chunk is a class with <begin, end, text> attributes > > For example, the text: "Hello World!" becomes: > > 1. 0, 5, "Hello" > 2. 5, 10, " Worl" > 3. 10, 12, "d!" > > The user can ask for an arbitrary span of text, for example: getText(6, > 11) should return "World". > > Currently I collect all the interesting chunks with the following query: > SELECT begin, end, text > FROM Chunk > WHERE > (begin <= 6 AND end >= 6) OR // the first interesting chunk > (begin >= 6 AND end <= 11) OR // all the other chunks > (begin <= 11 AND end >= 11) // the last interesting chunk > ORDER BY begin > Obviously such a query can be optimized with an index over begin, end > fields. > > I was thinking about another option, which is to link each Chunk with its > follower, for example: 1. -- next --> 2. -- next --> 3. > In this case the previous query could be implemented as a traversal: > TRAVERSE all() FROM (SELECT FROM Chunk WHERE begin <= 6 AND end > 6)WHILE > end <= 11 > > Considering that each Chunk has only one follower, do you think this > strategy would be more efficient? > > Cheers, > Riccardo > > -- --- You received this message because you are subscribed to the Google Groups "OrientDB" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
