Search in sources :

Example 1 with OIndexFullText

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

the class OQueryOperatorContainsText method filterRecords.

@SuppressWarnings({ "unchecked", "deprecation" })
@Override
public Collection<OIdentifiable> filterRecords(final ODatabase<?> iDatabase, final List<String> iTargetClasses, final OSQLFilterCondition iCondition, final Object iLeft, final Object iRight) {
    final String fieldName;
    if (iCondition.getLeft() instanceof OSQLFilterItemField)
        fieldName = iCondition.getLeft().toString();
    else
        fieldName = iCondition.getRight().toString();
    final String fieldValue;
    if (iCondition.getLeft() instanceof OSQLFilterItemField)
        fieldValue = iCondition.getRight().toString();
    else
        fieldValue = iCondition.getLeft().toString();
    final String className = iTargetClasses.get(0);
    final OProperty prop = ((OMetadataInternal) iDatabase.getMetadata()).getImmutableSchemaSnapshot().getClass(className).getProperty(fieldName);
    if (prop == null)
        // NO PROPERTY DEFINED
        return null;
    OIndex<?> fullTextIndex = null;
    for (final OIndex<?> indexDefinition : prop.getIndexes()) {
        if (indexDefinition instanceof OIndexFullText) {
            fullTextIndex = indexDefinition;
            break;
        }
    }
    if (fullTextIndex == null) {
        return null;
    }
    return (Collection<OIdentifiable>) fullTextIndex.get(fieldValue);
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OSQLFilterItemField(com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField) OMetadataInternal(com.orientechnologies.orient.core.metadata.OMetadataInternal) OIndexFullText(com.orientechnologies.orient.core.index.OIndexFullText) Collection(java.util.Collection)

Example 2 with OIndexFullText

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

the class OChainedIndexProxyFindBestIndexTest method mockFullTextIndex.

private OIndexFullText mockFullTextIndex() {
    final OIndexFullText uniqueIndex = mock(OIndexFullText.class);
    when(uniqueIndex.getInternal()).thenReturn(uniqueIndex);
    final OIndexDefinition definition = mock(OIndexDefinition.class);
    when(definition.getParamCount()).thenReturn(1);
    when(uniqueIndex.getDefinition()).thenReturn(definition);
    return uniqueIndex;
}
Also used : OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OIndexFullText(com.orientechnologies.orient.core.index.OIndexFullText)

Example 3 with OIndexFullText

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

the class OQueryOperatorContainsText method executeIndexQuery.

@Override
public OIndexCursor executeIndexQuery(OCommandContext iContext, OIndex<?> index, List<Object> keyParams, boolean ascSortOrder) {
    final OIndexDefinition indexDefinition = index.getDefinition();
    if (indexDefinition.getParamCount() > 1)
        return null;
    final OIndex<?> internalIndex = index.getInternal();
    OIndexCursor cursor;
    if (internalIndex instanceof OIndexFullText) {
        final Object key = indexDefinition.createValue(keyParams);
        final Object indexResult = index.get(key);
        if (indexResult == null || indexResult instanceof OIdentifiable)
            cursor = new OIndexCursorSingleValue((OIdentifiable) indexResult, key);
        else
            cursor = new OIndexCursorCollectionValue((Collection<OIdentifiable>) indexResult, key);
    } else
        return null;
    updateProfiler(iContext, internalIndex, keyParams, indexDefinition);
    return cursor;
}
Also used : OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OIndexCursorCollectionValue(com.orientechnologies.orient.core.index.OIndexCursorCollectionValue) OIndexCursorSingleValue(com.orientechnologies.orient.core.index.OIndexCursorSingleValue) OIndexCursor(com.orientechnologies.orient.core.index.OIndexCursor) OIndexFullText(com.orientechnologies.orient.core.index.OIndexFullText) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Aggregations

OIndexFullText (com.orientechnologies.orient.core.index.OIndexFullText)3 OIndexDefinition (com.orientechnologies.orient.core.index.OIndexDefinition)2 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)1 OIndexCursor (com.orientechnologies.orient.core.index.OIndexCursor)1 OIndexCursorCollectionValue (com.orientechnologies.orient.core.index.OIndexCursorCollectionValue)1 OIndexCursorSingleValue (com.orientechnologies.orient.core.index.OIndexCursorSingleValue)1 OMetadataInternal (com.orientechnologies.orient.core.metadata.OMetadataInternal)1 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)1 OSQLFilterItemField (com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField)1 Collection (java.util.Collection)1