use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.
the class LuceneMiscTest method dottedNotationTest.
@Test
public void dottedNotationTest() {
OrientGraphNoTx db = new OrientGraphNoTx("memory:dotted");
try {
OSchema schema = db.getRawGraph().getMetadata().getSchema();
OClass v = schema.getClass("V");
OClass e = schema.getClass("E");
OClass author = schema.createClass("Author");
author.setSuperClass(v);
author.createProperty("name", OType.STRING);
OClass song = schema.createClass("Song");
song.setSuperClass(v);
song.createProperty("title", OType.STRING);
OClass authorOf = schema.createClass("AuthorOf");
authorOf.createProperty("in", OType.LINK, song);
authorOf.setSuperClass(e);
db.command(new OCommandSQL("create index AuthorOf.in on AuthorOf (in) NOTUNIQUE")).execute();
db.command(new OCommandSQL("create index Song.title on Song (title) FULLTEXT ENGINE LUCENE")).execute();
OrientVertex authorVertex = db.addVertex("class:Author", new String[] { "name", "Bob Dylan" });
OrientVertex songVertex = db.addVertex("class:Song", new String[] { "title", "hurricane" });
authorVertex.addEdge("AuthorOf", songVertex);
List<Object> results = db.getRawGraph().command(new OCommandSQL("select from AuthorOf")).execute();
Assert.assertEquals(results.size(), 1);
results = db.getRawGraph().command(new OCommandSQL("select from AuthorOf where in.title lucene 'hurricane'")).execute();
Assert.assertEquals(results.size(), 1);
} finally {
db.drop();
}
}
use of com.orientechnologies.orient.core.sql.OCommandSQL 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.sql.OCommandSQL 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.sql.OCommandSQL in project orientdb by orientechnologies.
the class LuceneMultiFieldTest method init.
@Before
public void init() {
InputStream stream = ClassLoader.getSystemResourceAsStream("testLuceneIndex.sql");
db.command(new OCommandScript("sql", getScriptFromStream(stream))).execute();
db.command(new OCommandSQL("create index Song.title_author on Song (title,author) FULLTEXT ENGINE LUCENE METADATA {" + "\"title_index\":\"" + EnglishAnalyzer.class.getName() + "\" , " + "\"title_query\":\"" + EnglishAnalyzer.class.getName() + "\" , " + "\"author_index\":\"" + StandardAnalyzer.class.getName() + "\"}")).execute();
final ODocument index = db.getMetadata().getIndexManager().getIndex("Song.title_author").getMetadata();
assertThat(index.<Object>field("author_index")).isEqualTo(StandardAnalyzer.class.getName());
assertThat(index.<Object>field("title_index")).isEqualTo(EnglishAnalyzer.class.getName());
}
use of com.orientechnologies.orient.core.sql.OCommandSQL 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();
}
}
Aggregations