Search in sources :

Example 1 with OLuceneFullTextIndex

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;
}
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 2 with OLuceneFullTextIndex

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;
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) OLuceneFullTextIndex(com.orientechnologies.lucene.index.OLuceneFullTextIndex) MemoryIndex(org.apache.lucene.index.memory.MemoryIndex) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ParseException(com.orientechnologies.orient.core.sql.parser.ParseException) IOException(java.io.IOException)

Example 3 with OLuceneFullTextIndex

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);
    }
}
Also used : OLuceneFullTextIndex(com.orientechnologies.lucene.index.OLuceneFullTextIndex) OIndex(com.orientechnologies.orient.core.index.OIndex) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException)

Aggregations

OLuceneFullTextIndex (com.orientechnologies.lucene.index.OLuceneFullTextIndex)3 OIndex (com.orientechnologies.orient.core.index.OIndex)2 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)1 OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)1 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)1 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1 OSQLFilterItemField (com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField)1 ParseException (com.orientechnologies.orient.core.sql.parser.ParseException)1 IOException (java.io.IOException)1 IndexableField (org.apache.lucene.index.IndexableField)1 MemoryIndex (org.apache.lucene.index.memory.MemoryIndex)1