use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class LuceneMiscTest method testDoubleLucene.
// TODO Re-enable when removed check syntax on ODB
public void testDoubleLucene() {
OrientGraphNoTx graph = new OrientGraphNoTx("memory:doubleLucene");
try {
ODatabaseDocumentTx db = graph.getRawGraph();
db.command(new OCommandSQL("create class Test extends V")).execute();
db.command(new OCommandSQL("create property Test.attr1 string")).execute();
db.command(new OCommandSQL("create index Test.attr1 on Test (attr1) fulltext engine lucene")).execute();
db.command(new OCommandSQL("create property Test.attr2 string")).execute();
db.command(new OCommandSQL("create index Test.attr2 on Test (attr2) fulltext engine lucene")).execute();
db.command(new OCommandSQL("insert into Test set attr1='foo', attr2='bar'")).execute();
db.command(new OCommandSQL("insert into Test set attr1='bar', attr2='foo'")).execute();
List<ODocument> results = db.command(new OCommandSQL("select from Test where attr1 lucene 'foo*' OR attr2 lucene 'foo*'")).execute();
Assert.assertEquals(results.size(), 2);
results = db.command(new OCommandSQL("select from Test where attr1 lucene 'bar*' OR attr2 lucene 'bar*'")).execute();
Assert.assertEquals(results.size(), 2);
results = db.command(new OCommandSQL("select from Test where attr1 lucene 'foo*' AND attr2 lucene 'bar*'")).execute();
Assert.assertEquals(results.size(), 1);
results = db.command(new OCommandSQL("select from Test where attr1 lucene 'bar*' AND attr2 lucene 'foo*'")).execute();
Assert.assertEquals(results.size(), 1);
} finally {
graph.drop();
}
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class LuceneMiscTest method testNamedParams.
@Test
public void testNamedParams() {
OrientGraphNoTx graph = new OrientGraphNoTx("memory:doubleLucene");
try {
ODatabaseDocumentTx db = graph.getRawGraph();
db.command(new OCommandSQL("create class Test extends V")).execute();
db.command(new OCommandSQL("create property Test.attr1 string")).execute();
db.command(new OCommandSQL("create index Test.attr1 on Test (attr1) fulltext engine lucene")).execute();
db.command(new OCommandSQL("insert into Test set attr1='foo', attr2='bar'")).execute();
OSQLSynchQuery query = new OSQLSynchQuery("select from Test where attr1 lucene :name");
Map params = new HashMap();
params.put("name", "FOO or");
List results = db.command(query).execute(params);
Assert.assertEquals(results.size(), 1);
} finally {
graph.drop();
}
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class LuceneNullTest method testNullChangeToNotNullWithLists.
@Test
public void testNullChangeToNotNullWithLists() {
OrientGraphNoTx graph = new OrientGraphNoTx("memory:testNullChangeToNotNull");
try {
ODatabaseDocumentTx db = graph.getRawGraph();
db.command(new OCommandSQL("create class Test extends V")).execute();
db.command(new OCommandSQL("create property Test.names EMBEDDEDLIST STRING")).execute();
db.command(new OCommandSQL("create index Test.names on Test (names) fulltext engine lucene")).execute();
db.begin();
ODocument doc = new ODocument("Test");
db.save(doc);
db.commit();
db.begin();
doc.field("names", new String[] { "foo" });
db.save(doc);
db.commit();
OIndex<?> index = db.getMetadata().getIndexManager().getIndex("Test.names");
Assert.assertEquals(index.getSize(), 1);
} finally {
graph.drop();
}
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class LuceneTransactionEmbeddedQueryTest method txUpdateTestComplex.
@Test
public void txUpdateTestComplex() {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:updateTxTest");
db.create();
createSchema(db);
try {
OIndex<?> index = db.getMetadata().getIndexManager().getIndex("C1.p1");
Assert.assertEquals(index.getSize(), 0);
db.begin();
ODocument doc = new ODocument("c1");
doc.field("p1", new String[] { "abc" });
ODocument doc1 = new ODocument("c1");
doc1.field("p1", new String[] { "abc" });
db.save(doc1);
db.save(doc);
db.commit();
db.begin();
doc.field("p1", new String[] { "removed" });
db.save(doc);
String query = "select from C1 where p1 lucene \"abc\"";
List<ODocument> vertices = db.command(new OSQLSynchQuery<ODocument>(query)).execute();
Collection coll = (Collection) index.get("abc");
Assert.assertEquals(vertices.size(), 1);
Assert.assertEquals(coll.size(), 1);
Iterator iterator = coll.iterator();
int i = 0;
ORecordId rid = null;
while (iterator.hasNext()) {
rid = (ORecordId) iterator.next();
i++;
}
Assert.assertEquals(i, 1);
Assert.assertEquals(doc1.getIdentity().toString(), rid.getIdentity().toString());
Assert.assertEquals(index.getSize(), 2);
query = "select from C1 where p1 lucene \"removed\" ";
vertices = db.command(new OSQLSynchQuery<ODocument>(query)).execute();
coll = (Collection) index.get("removed");
Assert.assertEquals(vertices.size(), 1);
Assert.assertEquals(coll.size(), 1);
db.rollback();
query = "select from C1 where p1 lucene \"abc\" ";
vertices = db.command(new OSQLSynchQuery<ODocument>(query)).execute();
Assert.assertEquals(vertices.size(), 2);
Assert.assertEquals(index.getSize(), 2);
} finally {
db.drop();
}
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class LuceneTransactionEmbeddedQueryTest method txRemoveTest.
@Test
public void txRemoveTest() {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:updateTxTest");
db.create();
createSchema(db);
try {
db.begin();
ODocument doc = new ODocument("c1");
doc.field("p1", new String[] { "abc" });
OIndex<?> index = db.getMetadata().getIndexManager().getIndex("C1.p1");
db.save(doc);
String query = "select from C1 where p1 lucene \"abc\" ";
List<ODocument> vertices = db.command(new OSQLSynchQuery<ODocument>(query)).execute();
Assert.assertEquals(vertices.size(), 1);
Assert.assertEquals(index.getSize(), 1);
db.commit();
query = "select from C1 where p1 lucene \"abc\" ";
vertices = db.command(new OSQLSynchQuery<ODocument>(query)).execute();
Assert.assertEquals(vertices.size(), 1);
Assert.assertEquals(index.getSize(), 1);
db.begin();
db.delete(vertices.get(0));
query = "select from C1 where p1 lucene \"abc\" ";
vertices = db.command(new OSQLSynchQuery<ODocument>(query)).execute();
Collection coll = (Collection) index.get("abc");
Assert.assertEquals(vertices.size(), 0);
Assert.assertEquals(coll.size(), 0);
Iterator iterator = coll.iterator();
int i = 0;
while (iterator.hasNext()) {
iterator.next();
i++;
}
Assert.assertEquals(i, 0);
Assert.assertEquals(index.getSize(), 0);
db.rollback();
query = "select from C1 where p1 lucene \"abc\" ";
vertices = db.command(new OSQLSynchQuery<ODocument>(query)).execute();
Assert.assertEquals(vertices.size(), 1);
Assert.assertEquals(index.getSize(), 1);
} finally {
db.drop();
}
}
Aggregations