Search in sources :

Example 46 with OCommandSQL

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();
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Test(org.junit.Test)

Example 47 with OCommandSQL

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();
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 48 with OCommandSQL

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();
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) HashMap(java.util.HashMap) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 49 with OCommandSQL

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());
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) InputStream(java.io.InputStream) OCommandScript(com.orientechnologies.orient.core.command.script.OCommandScript) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) EnglishAnalyzer(org.apache.lucene.analysis.en.EnglishAnalyzer) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Before(org.junit.Before)

Example 50 with OCommandSQL

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();
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Aggregations

OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)621 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)422 Test (org.junit.Test)97 Test (org.testng.annotations.Test)93 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)83 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)79 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)78 ORID (com.orientechnologies.orient.core.id.ORID)64 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)61 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)54 Set (java.util.Set)53 HashMap (java.util.HashMap)45 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)42 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)41 List (java.util.List)25 Before (org.junit.Before)24 OStorage (com.orientechnologies.orient.core.storage.OStorage)23 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)23 ORecordId (com.orientechnologies.orient.core.id.ORecordId)21 Vertex (com.tinkerpop.blueprints.Vertex)19