Search in sources :

Example 6 with OSimpleKeyIndexDefinition

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;
}
Also used : OSimpleKeyIndexDefinition(com.orientechnologies.orient.core.index.OSimpleKeyIndexDefinition) OIndexTxAwareOneValue(com.orientechnologies.orient.core.index.OIndexTxAwareOneValue) OIndexFactory(com.orientechnologies.orient.core.index.OIndexFactory) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 7 with OSimpleKeyIndexDefinition

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);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSimpleKeyIndexDefinition(com.orientechnologies.orient.core.index.OSimpleKeyIndexDefinition) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 8 with OSimpleKeyIndexDefinition

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);
}
Also used : OSimpleKeyIndexDefinition(com.orientechnologies.orient.core.index.OSimpleKeyIndexDefinition) OClass(com.orientechnologies.orient.core.metadata.schema.OClass)

Example 9 with OSimpleKeyIndexDefinition

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);
}
Also used : OSimpleKeyIndexDefinition(com.orientechnologies.orient.core.index.OSimpleKeyIndexDefinition) BeforeClass(org.testng.annotations.BeforeClass)

Example 10 with OSimpleKeyIndexDefinition

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));
    }
}
Also used : OSimpleKeyIndexDefinition(com.orientechnologies.orient.core.index.OSimpleKeyIndexDefinition) OCommandSQLParsingException(com.orientechnologies.orient.core.sql.OCommandSQLParsingException) OIndexManagerProxy(com.orientechnologies.orient.core.index.OIndexManagerProxy) OCommandSQLParsingException(com.orientechnologies.orient.core.sql.OCommandSQLParsingException) Test(org.testng.annotations.Test)

Aggregations

OSimpleKeyIndexDefinition (com.orientechnologies.orient.core.index.OSimpleKeyIndexDefinition)12 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)5 Test (org.testng.annotations.Test)5 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)4 OIndex (com.orientechnologies.orient.core.index.OIndex)3 OIndexFactory (com.orientechnologies.orient.core.index.OIndexFactory)3 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)2 OIndexManagerProxy (com.orientechnologies.orient.core.index.OIndexManagerProxy)2 OIndexTxAwareOneValue (com.orientechnologies.orient.core.index.OIndexTxAwareOneValue)2 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)2 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 ORecordId (com.orientechnologies.orient.core.id.ORecordId)1 OCompositeKey (com.orientechnologies.orient.core.index.OCompositeKey)1 OIndexManager (com.orientechnologies.orient.core.index.OIndexManager)1 OIndexTxAwareMultiValue (com.orientechnologies.orient.core.index.OIndexTxAwareMultiValue)1 OIntentMassiveInsert (com.orientechnologies.orient.core.intent.OIntentMassiveInsert)1 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)1 OCommandSQLParsingException (com.orientechnologies.orient.core.sql.OCommandSQLParsingException)1 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)1 Edge (com.tinkerpop.blueprints.Edge)1