use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.
the class OSQLFunctionIn method fetchFromIndex.
private Object fetchFromIndex(OrientBaseGraph graph, OIdentifiable iFrom, Iterable<OIdentifiable> iTo, String[] iEdgeTypes) {
String edgeClassName = null;
if (iEdgeTypes == null) {
edgeClassName = "E";
} else if (iEdgeTypes.length == 1) {
edgeClassName = iEdgeTypes[0];
} else {
return null;
}
OClass edgeClass = graph.getRawGraph().getMetadata().getSchema().getClass(edgeClassName);
if (edgeClass == null) {
return null;
}
Set<OIndex<?>> indexes = edgeClass.getInvolvedIndexes("in", "out");
if (indexes == null || indexes.size() == 0) {
return null;
}
OIndex index = indexes.iterator().next();
OMultiCollectionIterator<OrientVertex> result = new OMultiCollectionIterator<OrientVertex>();
for (OIdentifiable to : iTo) {
OCompositeKey key = new OCompositeKey(iFrom, to);
Object indexResult = index.get(key);
if (indexResult instanceof OIdentifiable) {
indexResult = Collections.singleton(indexResult);
}
Set<OIdentifiable> identities = new HashSet<OIdentifiable>();
for (OIdentifiable edge : ((Iterable<OrientEdge>) indexResult)) {
identities.add((OIdentifiable) ((ODocument) edge.getRecord()).rawField("in"));
}
result.add(identities);
}
return result;
}
use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.
the class OSBTree method enhanceCompositeKey.
private K enhanceCompositeKey(K key, PartialSearchMode partialSearchMode) {
if (!(key instanceof OCompositeKey))
return key;
final OCompositeKey compositeKey = (OCompositeKey) key;
if (!(keySize == 1 || compositeKey.getKeys().size() == keySize || partialSearchMode.equals(PartialSearchMode.NONE))) {
final OCompositeKey fullKey = new OCompositeKey(compositeKey);
int itemsToAdd = keySize - fullKey.getKeys().size();
final Comparable<?> keyItem;
if (partialSearchMode.equals(PartialSearchMode.HIGHEST_BOUNDARY))
keyItem = ALWAYS_GREATER_KEY;
else
keyItem = ALWAYS_LESS_KEY;
for (int i = 0; i < itemsToAdd; i++) fullKey.addKey(keyItem);
return (K) fullKey;
}
return key;
}
use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.
the class OLuceneFullTextIndexEngine method putInManualindex.
private Document putInManualindex(Object key, OIdentifiable oIdentifiable) {
Document doc = new Document();
doc.add(OLuceneIndexType.createField(RID, oIdentifiable.getIdentity().toString(), Field.Store.YES));
if (key instanceof OCompositeKey) {
List<Object> keys = ((OCompositeKey) key).getKeys();
int k = 0;
for (Object o : keys) {
doc.add(OLuceneIndexType.createField("k" + k, o, Field.Store.NO));
k++;
}
} else if (key instanceof Collection) {
Collection<Object> keys = (Collection<Object>) key;
int k = 0;
for (Object o : keys) {
doc.add(OLuceneIndexType.createField("k" + k, o, Field.Store.NO));
k++;
}
} else {
doc.add(OLuceneIndexType.createField("k0", key, Field.Store.NO));
}
return doc;
}
use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.
the class EmbeddedObjectSerializationTest method testEmbeddedObjectSerialization.
public void testEmbeddedObjectSerialization() {
final ODocument originalDoc = new ODocument();
final OCompositeKey compositeKey = new OCompositeKey(123, "56", new Date(), new ORecordId("#0:12"));
originalDoc.field("compositeKey", compositeKey);
originalDoc.field("int", 12);
originalDoc.field("val", "test");
originalDoc.save();
final ODocument loadedDoc = database.load(originalDoc.getIdentity(), "*:-1", true);
Assert.assertNotSame(loadedDoc, originalDoc);
final OCompositeKey loadedCompositeKey = loadedDoc.field("compositeKey");
Assert.assertEquals(loadedCompositeKey, compositeKey);
originalDoc.delete();
}
use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.
the class OSQLFunctionOut method fetchFromIndex.
private Object fetchFromIndex(OrientBaseGraph graph, OIdentifiable iFrom, Iterable<OIdentifiable> iTo, String[] iEdgeTypes) {
String edgeClassName = null;
if (iEdgeTypes == null) {
edgeClassName = "E";
} else if (iEdgeTypes.length == 1) {
edgeClassName = iEdgeTypes[0];
} else {
return null;
}
OClass edgeClass = graph.getRawGraph().getMetadata().getSchema().getClass(edgeClassName);
if (edgeClass == null) {
return null;
}
Set<OIndex<?>> indexes = edgeClass.getInvolvedIndexes("out", "in");
if (indexes == null || indexes.size() == 0) {
return null;
}
OIndex index = indexes.iterator().next();
OMultiCollectionIterator<OrientVertex> result = new OMultiCollectionIterator<OrientVertex>();
for (OIdentifiable to : iTo) {
OCompositeKey key = new OCompositeKey(iFrom, to);
Object indexResult = index.get(key);
if (indexResult instanceof OIdentifiable) {
indexResult = Collections.singleton(indexResult);
}
Set<OIdentifiable> identities = new HashSet<OIdentifiable>();
for (OIdentifiable edge : ((Iterable<OrientEdge>) indexResult)) {
identities.add((OIdentifiable) ((ODocument) edge.getRecord()).rawField("in"));
}
result.add(identities);
}
return result;
}
Aggregations