0

We are using OrientDB in the embedded mode, and are hoping to access it directly with Java api calls (not using the SQL-ish language). We have an index, and need to perform a ranged search on it. Here is the only way I have found so far:

String startAt = createInternalOIndexSearchableKey(actualKey);
Index<Edge> index = graph.getIndex(indexName, Edge.class);
OrientIndex orientIndex = (OrientIndex) index;
OIndex oIndex = orientIndex.getUnderlying();
boolean INCLUSIVE = true;
boolean ASCENDING = true;
OIndexCursor cursor = oIndex.iterateEntriesMajor(startAt, INCLUSIVE, ASCENDING);
while(cursor.hasNext())
{
    Entry<Object, OIdentifiable> entry = cursor.nextEntry();
    ...process the entry here

It feels uncomfortable to be deviating so far from the normal public API. Especially the implementation of createInternalOIndexSearchableKey:

private String createInternalOIndexSearchableKey(String actualKey) 
{
    // NOTE: Keys passed to OIndex.iterateEntriesMajor must 
    // be in the (undocumented) format: EdgeLabel!=!ActualKey
    return KEY_CAN_DOWNLOAD_PUBCODETIMESTAMP + "!=!" + actualKey;
}

Is there a better way to do this?

1 Answers1

0

OIndex and OIndexCursor is a public api of Document database, so no worry, you can use it. However the main aim of API is to provide flexibility to SQL engine and other internal components, so it is not very convenient.

I would recommend you to use sql queries, they provide the same level of flexibility and more compact, that make their use more convenient.

enisher
  • 199
  • 5
  • 1
    Thanks for the response. I really prefer not to muck around with SQL strings in my java code, so a native solution would be ideal. But I will keep your advice in mind. (I would upvote your answer, but I don't yet have enough reputation). – Kevin Smith Jul 21 '14 at 17:29