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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations