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