Search in sources :

Example 1 with OIndexSearchResult

use of com.orientechnologies.orient.core.sql.OIndexSearchResult in project orientdb by orientechnologies.

the class OFilterOptimizerTest method testOptimizeFullOptimization.

@Test
public void testOptimizeFullOptimization() throws Exception {
    final OSQLFilter filter = OSQLEngine.getInstance().parseCondition("a = 3", null, "WHERE");
    final OSQLFilterCondition condition = filter.getRootCondition();
    final OIndexSearchResult searchResult = new OIndexSearchResult(condition.getOperator(), ((OSQLFilterItemField) condition.getLeft()).getFieldChain(), 3);
    optimizer.optimize(filter, searchResult);
    Assert.assertNull(filter.getRootCondition());
}
Also used : OIndexSearchResult(com.orientechnologies.orient.core.sql.OIndexSearchResult) Test(org.testng.annotations.Test)

Example 2 with OIndexSearchResult

use of com.orientechnologies.orient.core.sql.OIndexSearchResult in project orientdb by orientechnologies.

the class OFilterOptimizerTest method testOptimizePartialOptimizationMethod.

@Test
public void testOptimizePartialOptimizationMethod() throws Exception {
    final OSQLFilter filter = OSQLEngine.getInstance().parseCondition("a = 3 and b.asFloat() > 3.14", null, "WHERE");
    final OSQLFilterCondition condition = filter.getRootCondition();
    final OIndexSearchResult searchResult = new OIndexSearchResult(((OSQLFilterCondition) condition.getLeft()).getOperator(), ((OSQLFilterItemField) ((OSQLFilterCondition) condition.getLeft()).getLeft()).getFieldChain(), 3);
    optimizer.optimize(filter, searchResult);
    Assert.assertEquals(filter.getRootCondition().toString(), "(b.asfloat > 3.14)");
}
Also used : OIndexSearchResult(com.orientechnologies.orient.core.sql.OIndexSearchResult) Test(org.testng.annotations.Test)

Example 3 with OIndexSearchResult

use of com.orientechnologies.orient.core.sql.OIndexSearchResult in project orientdb by orientechnologies.

the class OLuceneOperatorUtil method buildOIndexSearchResult.

public static OIndexSearchResult buildOIndexSearchResult(OClass iSchemaClass, OSQLFilterCondition iCondition, List<OIndexSearchResult> iIndexSearchResults, OCommandContext context) {
    if (iCondition.getLeft() instanceof Collection) {
        OIndexSearchResult lastResult = null;
        Collection left = (Collection) iCondition.getLeft();
        int i = 0;
        Object lastValue = null;
        for (Object obj : left) {
            if (obj instanceof OSQLFilterItemField) {
                OSQLFilterItemField item = (OSQLFilterItemField) obj;
                Object value = null;
                if (iCondition.getRight() instanceof Collection) {
                    List<Object> right = (List<Object>) iCondition.getRight();
                    value = right.get(i);
                } else {
                    value = iCondition.getRight();
                }
                if (lastResult == null) {
                    lastResult = new OIndexSearchResult(iCondition.getOperator(), item.getFieldChain(), value);
                } else {
                    lastResult = lastResult.merge(new OIndexSearchResult(iCondition.getOperator(), item.getFieldChain(), value));
                }
            } else if (obj instanceof OSQLFilterItemVariable) {
                OSQLFilterItemVariable item = (OSQLFilterItemVariable) obj;
                Object value = null;
                if (iCondition.getRight() instanceof Collection) {
                    List<Object> right = (List<Object>) iCondition.getRight();
                    value = right.get(i);
                } else {
                    value = iCondition.getRight();
                }
                context.setVariable(item.toString(), value);
            }
            i++;
        }
        if (lastResult != null && OLuceneOperatorUtil.checkIndexExistence(iSchemaClass, lastResult))
            iIndexSearchResults.add(lastResult);
        return lastResult;
    } else {
        OIndexSearchResult result = OLuceneOperatorUtil.createIndexedProperty(iCondition, iCondition.getLeft());
        if (result == null)
            result = OLuceneOperatorUtil.createIndexedProperty(iCondition, iCondition.getRight());
        if (result == null)
            return null;
        if (OLuceneOperatorUtil.checkIndexExistence(iSchemaClass, result))
            iIndexSearchResults.add(result);
        return result;
    }
}
Also used : OSQLFilterItemField(com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField) Collection(java.util.Collection) List(java.util.List) OIndexSearchResult(com.orientechnologies.orient.core.sql.OIndexSearchResult) OSQLFilterItemVariable(com.orientechnologies.orient.core.sql.filter.OSQLFilterItemVariable)

Example 4 with OIndexSearchResult

use of com.orientechnologies.orient.core.sql.OIndexSearchResult in project orientdb by orientechnologies.

the class OLuceneOperatorUtil method createIndexedProperty.

public static OIndexSearchResult createIndexedProperty(final OSQLFilterCondition iCondition, final Object iItem) {
    if (iItem == null || !(iItem instanceof OSQLFilterItemField))
        return null;
    if (iCondition.getLeft() instanceof OSQLFilterItemField && iCondition.getRight() instanceof OSQLFilterItemField)
        return null;
    final OSQLFilterItemField item = (OSQLFilterItemField) iItem;
    if (item.hasChainOperators() && !item.isFieldChain())
        return null;
    final Object origValue = iCondition.getLeft() == iItem ? iCondition.getRight() : iCondition.getLeft();
    if (iCondition.getOperator() instanceof OQueryOperatorBetween || iCondition.getOperator() instanceof OQueryOperatorIn) {
        return new OIndexSearchResult(iCondition.getOperator(), item.getFieldChain(), origValue);
    }
    final Object value = OSQLHelper.getValue(origValue);
    if (value == null)
        return null;
    return new OIndexSearchResult(iCondition.getOperator(), item.getFieldChain(), value);
}
Also used : OQueryOperatorIn(com.orientechnologies.orient.core.sql.operator.OQueryOperatorIn) OSQLFilterItemField(com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField) OIndexSearchResult(com.orientechnologies.orient.core.sql.OIndexSearchResult) OQueryOperatorBetween(com.orientechnologies.orient.core.sql.operator.OQueryOperatorBetween)

Example 5 with OIndexSearchResult

use of com.orientechnologies.orient.core.sql.OIndexSearchResult in project orientdb by orientechnologies.

the class OFilterOptimizerTest method testOptimizeFullOptimizationComplex.

@Test
public void testOptimizeFullOptimizationComplex() throws Exception {
    final OSQLFilter filter = OSQLEngine.getInstance().parseCondition("a = 3 and b = 4", null, "WHERE");
    final OSQLFilterCondition condition = filter.getRootCondition();
    final OIndexSearchResult searchResult;
    {
        final OIndexSearchResult searchResult1;
        {
            final OSQLFilterCondition cnd = (OSQLFilterCondition) condition.getLeft();
            searchResult1 = new OIndexSearchResult(cnd.getOperator(), ((OSQLFilterItemField) cnd.getLeft()).getFieldChain(), 3);
        }
        final OIndexSearchResult searchResult2;
        {
            final OSQLFilterCondition cnd = (OSQLFilterCondition) condition.getRight();
            searchResult2 = new OIndexSearchResult(cnd.getOperator(), ((OSQLFilterItemField) cnd.getLeft()).getFieldChain(), 4);
        }
        searchResult = searchResult1.merge(searchResult2);
    }
    optimizer.optimize(filter, searchResult);
    Assert.assertNull(filter.getRootCondition());
}
Also used : OIndexSearchResult(com.orientechnologies.orient.core.sql.OIndexSearchResult) Test(org.testng.annotations.Test)

Aggregations

OIndexSearchResult (com.orientechnologies.orient.core.sql.OIndexSearchResult)6 Test (org.testng.annotations.Test)4 OSQLFilterItemField (com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField)2 OSQLFilterItemVariable (com.orientechnologies.orient.core.sql.filter.OSQLFilterItemVariable)1 OQueryOperatorBetween (com.orientechnologies.orient.core.sql.operator.OQueryOperatorBetween)1 OQueryOperatorIn (com.orientechnologies.orient.core.sql.operator.OQueryOperatorIn)1 Collection (java.util.Collection)1 List (java.util.List)1