use of com.xiaomi.linden.thrift.common.LindenFilter in project linden by XiaoMi.
the class TestBQL method testNotEqualPred.
@Test
public void testNotEqualPred() throws Exception {
String bql = "SELECT * FROM linden WHERE title <> 'red'";
LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
LindenBooleanFilter booleanFilter = new LindenBooleanFilter();
LindenFilter termFilter = LindenTermFilterBuilder.buildTermFilter("title", "red");
booleanFilter.addToFilters(new LindenBooleanSubFilter().setFilter(termFilter).setClause(LindenBooleanClause.MUST_NOT));
Assert.assertEquals(booleanFilter, lindenRequest.getFilter().getBooleanFilter());
bql = "SELECT * FROM linden WHERE title <> 're''d'";
lindenRequest = compiler.compile(bql).getSearchRequest();
booleanFilter = new LindenBooleanFilter();
termFilter = LindenTermFilterBuilder.buildTermFilter("title", "re'd");
booleanFilter.addToFilters(new LindenBooleanSubFilter().setFilter(termFilter).setClause(LindenBooleanClause.MUST_NOT));
Assert.assertEquals(booleanFilter, lindenRequest.getFilter().getBooleanFilter());
bql = "SELECT * FROM linden WHERE id <> 2000";
lindenRequest = compiler.compile(bql).getSearchRequest();
booleanFilter = new LindenBooleanFilter();
LindenFilter rangeFilter = LindenRangeFilterBuilder.buildRangeFilter("id", LindenType.LONG, "2000", "2000", true, true);
booleanFilter.addToFilters(new LindenBooleanSubFilter().setFilter(rangeFilter).setClause(LindenBooleanClause.MUST_NOT));
Assert.assertEquals(booleanFilter, lindenRequest.getFilter().getBooleanFilter());
bql = "SELECT * FROM linden WHERE id <> $id";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertEquals(null, lindenRequest.getFilter());
bql = "SELECT * FROM linden BY title <> 're''d'";
lindenRequest = compiler.compile(bql).getSearchRequest();
LindenBooleanQueryBuilder builder = new LindenBooleanQueryBuilder();
builder.addQuery(LindenRangeQueryBuilder.buildMatchAllQuery(), LindenBooleanClause.MUST);
builder.addQuery(LindenRangeQueryBuilder.buildTermQuery("title", "re'd"), LindenBooleanClause.MUST_NOT);
Assert.assertEquals(builder.build(), lindenRequest.getQuery());
bql = "SELECT * FROM linden BY id <> $id";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertEquals(LindenQueryBuilder.buildMatchAllQuery(), lindenRequest.getQuery());
}
use of com.xiaomi.linden.thrift.common.LindenFilter in project linden by XiaoMi.
the class RangeFilterConstructor method construct.
@Override
protected Filter construct(LindenFilter lindenFilter, LindenConfig config) throws IOException {
LindenRangeFilter lindenRangeFilter = lindenFilter.getRangeFilter();
LindenRange range = lindenRangeFilter.getRange();
LindenType type = range.getType();
String start = range.getStartValue();
String end = range.getEndValue();
String fieldName = range.getField();
boolean startClose = range.isStartClosed();
boolean endClose = range.isEndClosed();
Filter filter = null;
switch(type) {
case STRING:
case FACET:
filter = new TermRangeFilter(fieldName, bytesRefVal(start), bytesRefVal(end), startClose, endClose);
break;
case INTEGER:
filter = NumericRangeFilter.newIntRange(fieldName, intVal(start), intVal(end), startClose, endClose);
break;
case LONG:
filter = NumericRangeFilter.newLongRange(fieldName, longVal(start), longVal(end), startClose, endClose);
break;
case DOUBLE:
filter = NumericRangeFilter.newDoubleRange(fieldName, doubleVal(start), doubleVal(end), startClose, endClose);
break;
case FLOAT:
filter = NumericRangeFilter.newFloatRange(fieldName, floatVal(start), floatVal(end), startClose, endClose);
break;
}
return filter;
}
Aggregations