Search in sources :

Example 21 with OIndex

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

the class OServerCommandPostDatabase method exportClass.

protected void exportClass(final ODatabaseDocument db, final OJSONWriter json, final OClass cls) throws IOException {
    json.beginObject(2, true, null);
    json.writeAttribute(3, true, "name", cls.getName());
    json.writeAttribute(3, true, "superClass", cls.getSuperClass() != null ? cls.getSuperClass().getName() : "");
    json.writeAttribute(3, true, "alias", cls.getShortName());
    json.writeAttribute(3, true, "clusters", cls.getClusterIds());
    json.writeAttribute(3, true, "defaultCluster", cls.getDefaultClusterId());
    json.writeAttribute(3, true, "clusterSelection", cls.getClusterSelection().getName());
    try {
        json.writeAttribute(3, false, "records", db.countClass(cls.getName()));
    } catch (OSecurityAccessException e) {
        json.writeAttribute(3, false, "records", "? (Unauthorized)");
    }
    if (cls.properties() != null && cls.properties().size() > 0) {
        json.beginCollection(3, true, "properties");
        for (final OProperty prop : cls.properties()) {
            json.beginObject(4, true, null);
            json.writeAttribute(4, true, "name", prop.getName());
            if (prop.getLinkedClass() != null)
                json.writeAttribute(4, true, "linkedClass", prop.getLinkedClass().getName());
            if (prop.getLinkedType() != null)
                json.writeAttribute(4, true, "linkedType", prop.getLinkedType().toString());
            json.writeAttribute(4, true, "type", prop.getType().toString());
            json.writeAttribute(4, true, "mandatory", prop.isMandatory());
            json.writeAttribute(4, true, "readonly", prop.isReadonly());
            json.writeAttribute(4, true, "notNull", prop.isNotNull());
            json.writeAttribute(4, true, "min", prop.getMin());
            json.writeAttribute(4, true, "max", prop.getMax());
            json.endObject(3, true);
        }
        json.endCollection(1, true);
    }
    final Set<OIndex<?>> indexes = cls.getIndexes();
    if (!indexes.isEmpty()) {
        json.beginCollection(3, true, "indexes");
        for (final OIndex<?> index : indexes) {
            json.beginObject(4, true, null);
            json.writeAttribute(4, true, "name", index.getName());
            json.writeAttribute(4, true, "type", index.getType());
            final OIndexDefinition indexDefinition = index.getDefinition();
            if (indexDefinition != null && !indexDefinition.getFields().isEmpty())
                json.writeAttribute(4, true, "fields", indexDefinition.getFields());
            json.endObject(3, true);
        }
        json.endCollection(1, true);
    }
    json.endObject(1, false);
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OSecurityAccessException(com.orientechnologies.orient.core.exception.OSecurityAccessException) OIndex(com.orientechnologies.orient.core.index.OIndex)

Example 22 with OIndex

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

the class OSQLFunctionIn method fetchFromIndex.

private Object fetchFromIndex(OrientBaseGraph graph, OIdentifiable iFrom, Iterable<OIdentifiable> iTo, String[] iEdgeTypes) {
    String edgeClassName = null;
    if (iEdgeTypes == null) {
        edgeClassName = "E";
    } else if (iEdgeTypes.length == 1) {
        edgeClassName = iEdgeTypes[0];
    } else {
        return null;
    }
    OClass edgeClass = graph.getRawGraph().getMetadata().getSchema().getClass(edgeClassName);
    if (edgeClass == null) {
        return null;
    }
    Set<OIndex<?>> indexes = edgeClass.getInvolvedIndexes("in", "out");
    if (indexes == null || indexes.size() == 0) {
        return null;
    }
    OIndex index = indexes.iterator().next();
    OMultiCollectionIterator<OrientVertex> result = new OMultiCollectionIterator<OrientVertex>();
    for (OIdentifiable to : iTo) {
        OCompositeKey key = new OCompositeKey(iFrom, to);
        Object indexResult = index.get(key);
        if (indexResult instanceof OIdentifiable) {
            indexResult = Collections.singleton(indexResult);
        }
        Set<OIdentifiable> identities = new HashSet<OIdentifiable>();
        for (OIdentifiable edge : ((Iterable<OrientEdge>) indexResult)) {
            identities.add((OIdentifiable) ((ODocument) edge.getRecord()).rawField("in"));
        }
        result.add(identities);
    }
    return result;
}
Also used : OIndex(com.orientechnologies.orient.core.index.OIndex) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) OMultiCollectionIterator(com.orientechnologies.common.collection.OMultiCollectionIterator) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey) HashSet(java.util.HashSet) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 23 with OIndex

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

the class OLuceneTextOperator method involvedIndex.

protected OLuceneFullTextIndex involvedIndex(OIdentifiable iRecord, ODocument iCurrentResult, OSQLFilterCondition iCondition, Object iLeft, Object iRight) {
    ODocument doc = iRecord.getRecord();
    OClass cls = getDatabase().getMetadata().getSchema().getClass(doc.getClassName());
    if (isChained(iCondition.getLeft())) {
        OSQLFilterItemField chained = (OSQLFilterItemField) iCondition.getLeft();
        OSQLFilterItemField.FieldChain fieldChain = chained.getFieldChain();
        OClass oClass = cls;
        for (int i = 0; i < fieldChain.getItemCount() - 1; i++) {
            oClass = oClass.getProperty(fieldChain.getItemName(i)).getLinkedClass();
        }
        if (oClass != null) {
            cls = oClass;
        }
    }
    Set<OIndex<?>> classInvolvedIndexes = cls.getInvolvedIndexes(fields(iCondition));
    OLuceneFullTextIndex idx = null;
    for (OIndex<?> classInvolvedIndex : classInvolvedIndexes) {
        if (classInvolvedIndex.getInternal() instanceof OLuceneFullTextIndex) {
            idx = (OLuceneFullTextIndex) classInvolvedIndex.getInternal();
            break;
        }
    }
    return idx;
}
Also used : OLuceneFullTextIndex(com.orientechnologies.lucene.index.OLuceneFullTextIndex) OIndex(com.orientechnologies.orient.core.index.OIndex) OSQLFilterItemField(com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 24 with OIndex

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

the class LuceneMassiveInsertDeleteTest method loadCloseDelete.

@Test
public void loadCloseDelete() {
    ODocument city = new ODocument("City");
    int size = 1000;
    for (int i = 0; i < size; i++) {
        city.field("name", "Rome " + i);
        db.save(city);
        city.reset();
        city.setClassName("City");
    }
    String query = "select * from City where [name] LUCENE \"(name:Rome)\"";
    List<ODocument> docs = db.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertEquals(docs.size(), size);
    db.close();
    db.open("admin", "admin");
    docs = db.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertEquals(docs.size(), size);
    db.command(new OCommandSQL("delete vertex City")).execute();
    docs = db.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertEquals(docs.size(), 0);
    db.close();
    db.open("admin", "admin");
    docs = db.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertEquals(docs.size(), 0);
    db.getMetadata().reload();
    OIndex idx = db.getMetadata().getSchema().getClass("City").getClassIndex("City.name");
    idx.flush();
    Assert.assertEquals(idx.getSize(), 0);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OIndex(com.orientechnologies.orient.core.index.OIndex) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 25 with OIndex

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

the class LuceneInsertMultithreadTest method testConcurrentInsertWithIndex.

@Test
public void testConcurrentInsertWithIndex() throws Exception {
    databaseDocumentTx = new ODatabaseDocumentTx(url);
    if (!url.contains("remote:") && databaseDocumentTx.exists()) {
        databaseDocumentTx.open("admin", "admin");
        databaseDocumentTx.drop();
        databaseDocumentTx.create();
    } else {
        databaseDocumentTx.create();
    }
    OSchema schema = databaseDocumentTx.getMetadata().getSchema();
    if (schema.getClass("City") == null) {
        OClass oClass = schema.createClass("City");
        oClass.createProperty("name", OType.STRING);
        oClass.createIndex("City.name", "FULLTEXT", null, null, "LUCENE", new String[] { "name" });
    }
    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();
    for (int i = 0; i < THREADS + RTHREADS; ++i) threads[i].join();
    OIndex idx = schema.getClass("City").getClassIndex("City.name");
    Assert.assertEquals(idx.getSize(), THREADS * CYCLE);
    databaseDocumentTx.drop();
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OIndex(com.orientechnologies.orient.core.index.OIndex) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) 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