use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.
the class OrientIndex method buildKeyValueIndex.
private OIndex<?> buildKeyValueIndex(final ODocument metadata) {
final OIndexFactory factory = OIndexes.getFactory(OClass.INDEX_TYPE.DICTIONARY.toString(), null);
final OIndex<?> recordKeyValueIndex = new OIndexTxAwareOneValue(graph.getRawGraph(), (OIndex<OIdentifiable>) graph.getRawGraph().getMetadata().getIndexManager().createIndex("__@recordmap@___" + underlying.getName(), OClass.INDEX_TYPE.DICTIONARY.toString(), new OSimpleKeyIndexDefinition(factory.getLastVersion(), OType.LINK, OType.STRING), null, null, null));
final List<ODocument> entries = graph.getRawGraph().query(new OSQLSynchQuery<Object>("select from index:" + underlying.getName()));
for (ODocument entry : entries) {
final OIdentifiable rid = entry.field("rid");
if (rid != null)
recordKeyValueIndex.put(new OCompositeKey(rid, entry.field("key")), rid);
}
metadata.field(CONFIG_RECORD_MAP_NAME, recordKeyValueIndex.getName());
return recordKeyValueIndex;
}
use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.
the class OLuceneFacetManager method addFacetContext.
public void addFacetContext(OLuceneQueryContext queryContext, Object key) throws IOException {
queryContext.setFacet(true);
queryContext.setFacetField(facetField);
queryContext.setFacetConfig(config);
// queryContext.setfacetDim(facetDim);
queryContext.setReader(new DirectoryTaxonomyReader(getTaxDirectory(owner.getDatabase())));
if (key instanceof OCompositeKey) {
List<Object> keys = ((OCompositeKey) key).getKeys();
for (Object o : keys) {
if (o instanceof Map) {
String drillDown = (String) ((Map) o).get("drillDown");
queryContext.setDrillDownQuery(drillDown);
}
}
}
}
use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.
the class OLuceneIndexType method createExactQuery.
public static Query createExactQuery(OIndexDefinition index, Object key) {
Query query = null;
if (key instanceof String) {
final BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder();
if (index.getFields().size() > 0) {
for (String idx : index.getFields()) {
queryBuilder.add(new TermQuery(new Term(idx, key.toString())), BooleanClause.Occur.SHOULD);
}
} else {
queryBuilder.add(new TermQuery(new Term(OLuceneIndexEngineAbstract.KEY, key.toString())), BooleanClause.Occur.SHOULD);
}
query = queryBuilder.build();
} else if (key instanceof OCompositeKey) {
final BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder();
int i = 0;
OCompositeKey keys = (OCompositeKey) key;
for (String idx : index.getFields()) {
String val = (String) keys.getKeys().get(i);
queryBuilder.add(new TermQuery(new Term(idx, val)), BooleanClause.Occur.MUST);
i++;
}
query = queryBuilder.build();
}
return query;
}
use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.
the class OTransactionOptimisticProxy method fillIndexOperations.
private void fillIndexOperations(final ODocument remoteIndexEntries) {
for (Entry<String, Object> indexEntry : remoteIndexEntries) {
final String indexName = indexEntry.getKey();
final ODocument indexDoc = (ODocument) indexEntry.getValue();
if (indexDoc == null)
continue;
OTransactionIndexChanges transactionIndexChanges = indexEntries.get(indexEntry.getKey());
if (transactionIndexChanges == null) {
transactionIndexChanges = new OTransactionIndexChanges();
indexEntries.put(indexEntry.getKey(), transactionIndexChanges);
}
final Boolean clearAll = indexDoc.field("clear");
if (clearAll != null && clearAll)
transactionIndexChanges.setCleared();
final Collection<ODocument> entries = indexDoc.field("entries");
if (entries == null)
continue;
for (final ODocument entry : entries) {
final List<ODocument> operations = entry.field("ops");
if (operations == null)
continue;
final Object key;
try {
ODocument keyContainer;
if (protocolVersion <= OChannelBinaryProtocol.PROTOCOL_VERSION_24) {
final String serializedKey = OStringSerializerHelper.decode((String) entry.field("k"));
if (serializedKey.equals("*"))
keyContainer = null;
else {
keyContainer = new ODocument();
keyContainer.setLazyLoad(false);
ORecordSerializerSchemaAware2CSV.INSTANCE.fromString(serializedKey, keyContainer, null);
}
} else {
keyContainer = entry.field("k");
}
if (keyContainer != null) {
final Object storedKey = keyContainer.field("key");
if (storedKey instanceof List)
key = new OCompositeKey((List<? extends Comparable<?>>) storedKey);
else if (Boolean.TRUE.equals(keyContainer.field("binary"))) {
key = OStreamSerializerAnyStreamable.INSTANCE.fromStream((byte[]) storedKey);
} else
key = storedKey;
} else
key = null;
} catch (IOException ioe) {
throw OException.wrapException(new OTransactionException("Error during index changes deserialization. "), ioe);
}
for (final ODocument op : operations) {
final int operation = (Integer) op.rawField("o");
final OTransactionIndexChanges.OPERATION indexOperation = OTransactionIndexChanges.OPERATION.values()[operation];
final OIdentifiable value = op.field("v");
transactionIndexChanges.getChangesPerKey(key).add(value, indexOperation);
if (value == null)
continue;
final ORID rid = value.getIdentity();
List<OTransactionRecordIndexOperation> txIndexOperations = recordIndexOperations.get(rid);
if (txIndexOperations == null) {
txIndexOperations = new ArrayList<OTransactionRecordIndexOperation>();
recordIndexOperations.put(rid, txIndexOperations);
}
txIndexOperations.add(new OTransactionRecordIndexOperation(indexName, key, indexOperation));
}
}
}
}
use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.
the class ByteArrayKeyTest method testAutomaticCompositeUsage.
public void testAutomaticCompositeUsage() {
byte[] key1 = new byte[] { 1, 2, 3 };
byte[] key2 = new byte[] { 4, 5, 6 };
ODocument doc1 = new ODocument("CompositeByteArrayKeyTest");
doc1.field("byteArrayKey", key1);
doc1.field("intKey", 1);
doc1.save();
ODocument doc2 = new ODocument("CompositeByteArrayKeyTest");
doc2.field("byteArrayKey", key2);
doc2.field("intKey", 2);
doc2.save();
OIndex<?> index = database.getMetadata().getIndexManager().getIndex("compositeByteArrayKey");
Assert.assertEquals(index.get(new OCompositeKey(key1, 1)), doc1);
Assert.assertEquals(index.get(new OCompositeKey(key2, 2)), doc2);
}
Aggregations