use of com.orientechnologies.orient.core.index.OSimpleKeyIndexDefinition 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.OSimpleKeyIndexDefinition in project orientdb by orientechnologies.
the class LuceneManualIndexTest method shouldCreateManualIndexWithJavaApi.
@Test
public void shouldCreateManualIndexWithJavaApi() throws Exception {
ODocument meta = new ODocument().field("analyzer", StandardAnalyzer.class.getName());
OIndex<?> index = db.getMetadata().getIndexManager().createIndex("apiManual", OClass.INDEX_TYPE.FULLTEXT.toString(), new OSimpleKeyIndexDefinition(1, OType.STRING, OType.STRING), null, null, meta, OLuceneIndexFactory.LUCENE_ALGORITHM);
db.command(new OCommandSQL("insert into index:apiManual (key,rid) values(['Enrico','London'],#5:0) ")).execute();
db.command(new OCommandSQL("insert into index:apiManual (key,rid) values(['Luca','Rome'],#5:0) ")).execute();
db.command(new OCommandSQL("insert into index:apiManual (key,rid) values(['Luigi','Rome'],#5:0) ")).execute();
Assert.assertEquals(index.getSize(), 3);
List<ODocument> docs = db.command(new OSQLSynchQuery("select from index:apiManual where key LUCENE '(k0:Enrico)'")).execute();
Assert.assertEquals(docs.size(), 1);
docs = db.command(new OSQLSynchQuery("select from index:apiManual where key LUCENE '(k0:Luca)'")).execute();
Assert.assertEquals(docs.size(), 1);
docs = db.command(new OSQLSynchQuery("select from index:apiManual where key LUCENE '(k1:Rome)'")).execute();
Assert.assertEquals(docs.size(), 2);
docs = db.command(new OSQLSynchQuery("select from index:apiManual where key LUCENE '(k1:London)'")).execute();
Assert.assertEquals(docs.size(), 1);
}
use of com.orientechnologies.orient.core.index.OSimpleKeyIndexDefinition in project orientdb by orientechnologies.
the class ByteArrayKeyTest method beforeClass.
@BeforeClass
public void beforeClass() throws Exception {
super.beforeClass();
final OClass byteArrayKeyTest = database.getMetadata().getSchema().createClass("ByteArrayKeyTest");
byteArrayKeyTest.createProperty("byteArrayKey", OType.BINARY);
byteArrayKeyTest.createIndex("byteArrayKeyIndex", OClass.INDEX_TYPE.UNIQUE, "byteArrayKey");
final OClass compositeByteArrayKeyTest = database.getMetadata().getSchema().createClass("CompositeByteArrayKeyTest");
compositeByteArrayKeyTest.createProperty("byteArrayKey", OType.BINARY);
compositeByteArrayKeyTest.createProperty("intKey", OType.INTEGER);
compositeByteArrayKeyTest.createIndex("compositeByteArrayKey", OClass.INDEX_TYPE.UNIQUE, "byteArrayKey", "intKey");
database.getMetadata().getIndexManager().createIndex("byte-array-manualIndex-notunique", "NOTUNIQUE", new OSimpleKeyIndexDefinition(-1, OType.BINARY), null, null, null);
}
use of com.orientechnologies.orient.core.index.OSimpleKeyIndexDefinition in project orientdb by orientechnologies.
the class IndexTxAwareMultiValueGetEntriesTest method beforeClass.
@BeforeClass
public void beforeClass() throws Exception {
super.beforeClass();
database.getMetadata().getIndexManager().createIndex("idxTxAwareMultiValueGetEntriesTest", "NOTUNIQUE", new OSimpleKeyIndexDefinition(-1, OType.INTEGER), null, null, null);
}
use of com.orientechnologies.orient.core.index.OSimpleKeyIndexDefinition in project orientdb by orientechnologies.
the class IndexManagerTest method testCreateSimpleKeyInvalidNameIndex.
@Test
public void testCreateSimpleKeyInvalidNameIndex() {
final OIndexManagerProxy indexManager = database.getMetadata().getIndexManager();
try {
indexManager.createIndex("simple:key", OClass.INDEX_TYPE.UNIQUE.toString(), new OSimpleKeyIndexDefinition(-1, OType.INTEGER), null, null, null);
fail();
} catch (Exception e) {
Throwable cause = e;
while (cause.getCause() != null) cause = cause.getCause();
assertTrue((cause instanceof IllegalArgumentException) || (cause instanceof OCommandSQLParsingException));
}
}
Aggregations