Search in sources :

Example 46 with OIndex

use of com.orientechnologies.orient.core.index.OIndex in project orientdb by orientechnologies.

the class LuceneInsertIntegrityRemoteTest method testInsertUpdateWithIndex.

@Test
@Ignore
public void testInsertUpdateWithIndex() throws Exception {
    db.getMetadata().reload();
    OSchema schema = db.getMetadata().getSchema();
    ODocument doc = new ODocument("City");
    doc.field("name", "Rome");
    db.begin();
    db.save(doc);
    db.commit();
    OIndex idx = schema.getClass("City").getClassIndex("City.name");
    Collection<?> coll = (Collection<?>) idx.get("Rome");
    Assert.assertEquals(coll.size(), 1);
    doc = db.load((ORID) coll.iterator().next());
    Assert.assertEquals(doc.field("name"), "Rome");
    db.begin();
    doc.field("name", "London");
    db.save(doc);
    db.commit();
    coll = (Collection<?>) idx.get("Rome");
    Assert.assertEquals(coll.size(), 0);
    coll = (Collection<?>) idx.get("London");
    Assert.assertEquals(coll.size(), 1);
    doc = db.load((ORID) coll.iterator().next());
    Assert.assertEquals(doc.field("name"), "London");
    db.begin();
    doc.field("name", "Berlin");
    db.save(doc);
    db.commit();
    doc = db.load(doc.getIdentity(), null, true);
    Assert.assertEquals(doc.field("name"), "Berlin");
    coll = (Collection<?>) idx.get("Rome");
    Assert.assertEquals(coll.size(), 0);
    coll = (Collection<?>) idx.get("London");
    Assert.assertEquals(coll.size(), 0);
    coll = (Collection<?>) idx.get("Berlin");
    Assert.assertEquals(idx.getSize(), 1);
    Assert.assertEquals(coll.size(), 1);
    Thread.sleep(1000);
    // FIXME
    // initDB();
    // 
    doc = db.load(doc.getIdentity(), null, true);
    Assert.assertEquals(doc.field("name"), "Berlin");
    schema = db.getMetadata().getSchema();
    idx = schema.getClass("City").getClassIndex("City.name");
    Assert.assertEquals(idx.getSize(), 1);
    coll = (Collection<?>) idx.get("Rome");
    Assert.assertEquals(coll.size(), 0);
    coll = (Collection<?>) idx.get("London");
    Assert.assertEquals(coll.size(), 0);
    coll = (Collection<?>) idx.get("Berlin");
    Assert.assertEquals(coll.size(), 1);
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OIndex(com.orientechnologies.orient.core.index.OIndex) Collection(java.util.Collection) ORID(com.orientechnologies.orient.core.id.ORID) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 47 with OIndex

use of com.orientechnologies.orient.core.index.OIndex in project orientdb by orientechnologies.

the class LuceneInsertReadMultithreadTest method testConcurrentInsertWithIndex.

@Test
public void testConcurrentInsertWithIndex() throws Exception {
    db.getMetadata().reload();
    OSchema schema = db.getMetadata().getSchema();
    Thread[] threads = new Thread[THREADS + RTHREADS];
    for (int i = 0; i < THREADS; ++i) threads[i] = new Thread(new LuceneInsertThread(CYCLE), "ConcurrentWriteTest" + i);
    for (int i = THREADS; i < THREADS + RTHREADS; ++i) threads[i] = new Thread(new LuceneReadThread(CYCLE), "ConcurrentReadTest" + i);
    for (int i = 0; i < THREADS + RTHREADS; ++i) threads[i].start();
    System.out.println("Started LuceneInsertReadMultithreadTest test, waiting for " + threads.length + " threads to complete...");
    for (int i = 0; i < THREADS + RTHREADS; ++i) threads[i].join();
    System.out.println("LuceneInsertReadMultithreadTest all threads completed");
    OIndex idx = schema.getClass("City").getClassIndex("City.name");
    Assert.assertEquals(idx.getSize(), THREADS * CYCLE);
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OIndex(com.orientechnologies.orient.core.index.OIndex) Test(org.junit.Test)

Example 48 with OIndex

use of com.orientechnologies.orient.core.index.OIndex in project orientdb by orientechnologies.

the class LuceneInsertUpdateTransactionTest method testInsertUpdateTransactionWithIndex.

@Test
public void testInsertUpdateTransactionWithIndex() throws Exception {
    OSchema schema = db.getMetadata().getSchema();
    schema.reload();
    db.begin();
    ODocument doc = new ODocument("City");
    doc.field("name", "Rome");
    db.save(doc);
    OIndex idx = schema.getClass("City").getClassIndex("City.name");
    Assert.assertNotNull(idx);
    Collection<?> coll = (Collection<?>) idx.get("Rome");
    Assert.assertEquals(coll.size(), 1);
    db.rollback();
    coll = (Collection<?>) idx.get("Rome");
    Assert.assertEquals(coll.size(), 0);
    db.begin();
    doc = new ODocument("City");
    doc.field("name", "Rome");
    db.save(doc);
    OUser user = new OUser("test", "test");
    db.save(user.getDocument());
    db.commit();
    coll = (Collection<?>) idx.get("Rome");
    Assert.assertEquals(coll.size(), 1);
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OIndex(com.orientechnologies.orient.core.index.OIndex) Collection(java.util.Collection) OUser(com.orientechnologies.orient.core.metadata.security.OUser) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 49 with OIndex

use of com.orientechnologies.orient.core.index.OIndex in project orientdb by orientechnologies.

the class LuceneListIndexingTest method testIndexingList.

@Test
public void testIndexingList() throws Exception {
    OSchema schema = db.getMetadata().getSchema();
    // Rome
    ODocument doc = new ODocument("City");
    doc.field("name", "Rome");
    doc.field("tags", new ArrayList<String>() {

        {
            add("Beautiful");
            add("Touristic");
            add("Sunny");
        }
    });
    db.save(doc);
    OIndex tagsIndex = schema.getClass("City").getClassIndex("City.tags");
    Collection<?> coll = (Collection<?>) tagsIndex.get("Sunny");
    assertThat(coll).hasSize(1);
    doc = db.load((ORID) coll.iterator().next());
    assertThat(doc.<String>field("name")).isEqualTo("Rome");
    // London
    doc = new ODocument("City");
    doc.field("name", "London");
    doc.field("tags", new ArrayList<String>() {

        {
            add("Beautiful");
            add("Touristic");
            add("Sunny");
        }
    });
    db.save(doc);
    coll = (Collection<?>) tagsIndex.get("Sunny");
    assertThat(coll).hasSize(2);
    // modify london: it is rainy
    List<String> tags = doc.field("tags");
    tags.remove("Sunny");
    tags.add("Rainy");
    db.save(doc);
    coll = (Collection<?>) tagsIndex.get("Rainy");
    assertThat(coll).hasSize(1);
    coll = (Collection<?>) tagsIndex.get("Beautiful");
    assertThat(coll).hasSize(2);
    coll = (Collection<?>) tagsIndex.get("Sunny");
    assertThat(coll).hasSize(1);
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OIndex(com.orientechnologies.orient.core.index.OIndex) Collection(java.util.Collection) ORID(com.orientechnologies.orient.core.id.ORID) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 50 with OIndex

use of com.orientechnologies.orient.core.index.OIndex in project orientdb by orientechnologies.

the class LuceneListIndexingTest method testCompositeIndexList.

@Test
public void testCompositeIndexList() {
    OSchema schema = db.getMetadata().getSchema();
    ODocument doc = new ODocument("Person");
    doc.field("name", "Enrico");
    doc.field("tags", new ArrayList<String>() {

        {
            add("Funny");
            add("Tall");
            add("Geek");
        }
    });
    db.save(doc);
    OIndex idx = schema.getClass("Person").getClassIndex("Person.name_tags");
    Collection<?> coll = (Collection<?>) idx.get("Enrico");
    assertThat(coll).hasSize(3);
    doc = new ODocument("Person");
    doc.field("name", "Jared");
    doc.field("tags", new ArrayList<String>() {

        {
            add("Funny");
            add("Tall");
        }
    });
    db.save(doc);
    coll = (Collection<?>) idx.get("Jared");
    assertThat(coll).hasSize(2);
    List<String> tags = doc.field("tags");
    tags.remove("Funny");
    tags.add("Geek");
    db.save(doc);
    coll = (Collection<?>) idx.get("Funny");
    assertThat(coll).hasSize(1);
    coll = (Collection<?>) idx.get("Geek");
    assertThat(coll).hasSize(2);
    List<?> query = db.query(new OSQLSynchQuery<Object>("select from Person where [name,tags] lucene 'Enrico'"));
    assertThat(query).hasSize(1);
    query = db.query(new OSQLSynchQuery<Object>("select from (select from Person where [name,tags] lucene 'Enrico')"));
    assertThat(query).hasSize(1);
    query = db.query(new OSQLSynchQuery<Object>("select from Person where [name,tags] lucene 'Jared'"));
    assertThat(query).hasSize(1);
    query = db.query(new OSQLSynchQuery<Object>("select from Person where [name,tags] lucene 'Funny'"));
    assertThat(query).hasSize(1);
    query = db.query(new OSQLSynchQuery<Object>("select from Person where [name,tags] lucene 'Geek'"));
    assertThat(query).hasSize(2);
    query = db.query(new OSQLSynchQuery<Object>("select from Person where [name,tags] lucene '(name:Enrico AND tags:Geek)'"));
    assertThat(query).hasSize(1);
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OIndex(com.orientechnologies.orient.core.index.OIndex) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) Collection(java.util.Collection) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Aggregations

OIndex (com.orientechnologies.orient.core.index.OIndex)98 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)54 Test (org.testng.annotations.Test)50 OIndexDefinition (com.orientechnologies.orient.core.index.OIndexDefinition)26 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)20 OIndexManager (com.orientechnologies.orient.core.index.OIndexManager)18 OCompositeIndexDefinition (com.orientechnologies.orient.core.index.OCompositeIndexDefinition)16 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)16 Test (org.junit.Test)14 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)12 Collection (java.util.Collection)11 OPropertyIndexDefinition (com.orientechnologies.orient.core.index.OPropertyIndexDefinition)9 OPropertyMapIndexDefinition (com.orientechnologies.orient.core.index.OPropertyMapIndexDefinition)8 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)8 HashSet (java.util.HashSet)6 OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)5 OIndexManagerProxy (com.orientechnologies.orient.core.index.OIndexManagerProxy)5 OIndexUnique (com.orientechnologies.orient.core.index.OIndexUnique)5 Map (java.util.Map)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)4