use of com.orientechnologies.lucene.index.OLuceneFullTextIndex 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.lucene.index.OLuceneFullTextIndex in project orientdb by orientechnologies.
the class OLuceneTextOperator method evaluateRecord.
@Override
public Object evaluateRecord(OIdentifiable iRecord, ODocument iCurrentResult, OSQLFilterCondition iCondition, Object iLeft, Object iRight, OCommandContext iContext) {
OLuceneFullTextIndex index = involvedIndex(iRecord, iCurrentResult, iCondition, iLeft, iRight);
if (index == null) {
throw new OCommandExecutionException("Cannot evaluate lucene condition without index configuration.");
}
MemoryIndex memoryIndex = (MemoryIndex) iContext.getVariable(MEMORY_INDEX);
if (memoryIndex == null) {
memoryIndex = new MemoryIndex();
iContext.setVariable(MEMORY_INDEX, memoryIndex);
}
memoryIndex.reset();
try {
for (IndexableField field : index.buildDocument(iLeft).getFields()) {
memoryIndex.addField(field.name(), field.tokenStream(index.indexAnalyzer(), null));
}
return memoryIndex.search(index.buildQuery(iRight)) > 0.0f;
} catch (ParseException e) {
OLogManager.instance().error(this, "error occurred while building query", e);
} catch (IOException e) {
OLogManager.instance().error(this, "error occurred while building memory index", e);
}
return null;
}
use of com.orientechnologies.lucene.index.OLuceneFullTextIndex in project orientdb by orientechnologies.
the class OLuceneIndexFactory method onDrop.
@Override
public void onDrop(final ODatabaseInternal db) {
try {
if (db.isClosed())
return;
OLogManager.instance().debug(this, "Dropping Lucene indexes...");
for (OIndex idx : db.getMetadata().getIndexManager().getIndexes()) {
if (idx.getInternal() instanceof OLuceneFullTextIndex) {
OLogManager.instance().debug(this, "- index '%s'", idx.getName());
idx.delete();
}
}
} catch (Exception e) {
OLogManager.instance().warn(this, "Error on dropping Lucene indexes", e);
}
}
Aggregations