Search in sources :

Example 11 with LindenSearchRequest

use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.

the class TestBQL method testNullPredicate.

@Test
public void testNullPredicate() throws Exception {
    String bql = "SELECT * FROM linden  WHERE id IS NOT NULL";
    LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
    LindenFilter filter = LindenNotNullFieldFilterBuilder.buildNotNullFieldFilterBuilder("id", false);
    Assert.assertEquals(filter, lindenRequest.getFilter());
    bql = "SELECT * FROM linden WHERE title IS NULL";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    filter = LindenNotNullFieldFilterBuilder.buildNotNullFieldFilterBuilder("title", true);
    Assert.assertEquals(filter, lindenRequest.getFilter());
    bql = "SELECT * FROM linden by title IS NULL";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    filter = LindenNotNullFieldFilterBuilder.buildNotNullFieldFilterBuilder("title", true);
    LindenQuery query = LindenQueryBuilder.buildFilteredQuery(LindenQueryBuilder.buildMatchAllQuery(), filter);
    Assert.assertEquals(query, lindenRequest.getQuery());
}
Also used : LindenFilter(com.xiaomi.linden.thrift.common.LindenFilter) LindenQuery(com.xiaomi.linden.thrift.common.LindenQuery) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 12 with LindenSearchRequest

use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.

the class TestBQL method testBetweenPred.

@Test
public void testBetweenPred() throws Exception {
    String bql = "SELECT * FROM linden WHERE id BETWEEN 2000 AND 2001";
    LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
    LindenFilter filter = LindenRangeFilterBuilder.buildRangeFilter("id", LindenType.LONG, "2000", "2001", true, true);
    Assert.assertEquals(filter, lindenRequest.getFilter());
    bql = "SELECT * FROM linden WHERE title BETWEEN 'black' AND \"yellow\"";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    filter = LindenRangeFilterBuilder.buildRangeFilter("title", LindenType.STRING, "black", "yellow", true, true);
    Assert.assertEquals(filter, lindenRequest.getFilter());
    bql = "SELECT * FROM linden WHERE id NOT BETWEEN 2000 AND 2002";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    LindenFilter filter1 = LindenRangeFilterBuilder.buildRangeFilter("id", LindenType.LONG, null, "2000", false, false);
    LindenFilter filter2 = LindenRangeFilterBuilder.buildRangeFilter("id", LindenType.LONG, "2002", null, false, false);
    LindenBooleanFilter booleanFilter = new LindenBooleanFilter();
    booleanFilter.addToFilters(new LindenBooleanSubFilter().setFilter(filter1).setClause(LindenBooleanClause.SHOULD));
    booleanFilter.addToFilters(new LindenBooleanSubFilter().setFilter(filter2).setClause(LindenBooleanClause.SHOULD));
    LindenFilter expectedFilter = new LindenFilter().setBooleanFilter(booleanFilter);
    Assert.assertEquals(expectedFilter, lindenRequest.getFilter());
    bql = "SELECT * FROM linden WHERE title BETWEEN $a AND $b";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    Assert.assertEquals(null, lindenRequest.getFilter());
    bql = "SELECT * FROM linden WHERE title BETWEEN 'black' AND \"yellow\"";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    filter = LindenRangeFilterBuilder.buildRangeFilter("title", LindenType.STRING, "black", "yellow", true, true);
    Assert.assertEquals(filter, lindenRequest.getFilter());
    bql = "SELECT * FROM linden by id NOT BETWEEN 2000 AND 2002";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    LindenQuery query1 = LindenRangeQueryBuilder.buildRangeQuery("id", LindenType.LONG, null, "2000", false, false);
    LindenQuery query2 = LindenRangeQueryBuilder.buildRangeQuery("id", LindenType.LONG, "2002", null, false, false);
    LindenBooleanQueryBuilder builder = new LindenBooleanQueryBuilder();
    builder.addQuery(query1, LindenBooleanClause.SHOULD);
    builder.addQuery(query2, LindenBooleanClause.SHOULD);
    Assert.assertEquals(builder.build(), lindenRequest.getQuery());
    bql = "SELECT * FROM linden by title BETWEEN 'black' AND \"yel\"\"low\"";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    LindenQuery query = LindenRangeQueryBuilder.buildRangeQuery("title", LindenType.STRING, "black", "yel\"low", true, true);
    Assert.assertEquals(query, lindenRequest.getQuery());
}
Also used : LindenFilter(com.xiaomi.linden.thrift.common.LindenFilter) LindenBooleanFilter(com.xiaomi.linden.thrift.common.LindenBooleanFilter) LindenQuery(com.xiaomi.linden.thrift.common.LindenQuery) LindenBooleanSubFilter(com.xiaomi.linden.thrift.common.LindenBooleanSubFilter) LindenBooleanQueryBuilder(com.xiaomi.linden.thrift.builder.query.LindenBooleanQueryBuilder) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 13 with LindenSearchRequest

use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.

the class TestBQL method testSnippet.

@Test
public void testSnippet() {
    String bql = "SELECT * FROM linden QUERY title LIKE 'sed*' snippet title, content";
    LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
    SnippetParam expected = new SnippetParam();
    expected.addToFields(new SnippetField("title"));
    expected.addToFields(new SnippetField("content"));
    Assert.assertEquals(expected, lindenRequest.getSnippetParam());
}
Also used : SnippetField(com.xiaomi.linden.thrift.common.SnippetField) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) SnippetParam(com.xiaomi.linden.thrift.common.SnippetParam) Test(org.junit.Test)

Example 14 with LindenSearchRequest

use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.

the class TestBQL method testInPredicate.

@Test
public void testInPredicate() {
    String bql = "select * from linden where id in (1, 2, 3)";
    LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
    LindenBooleanFilterBuilder filterBuilder = new LindenBooleanFilterBuilder();
    filterBuilder.addFilter(LindenRangeFilterBuilder.buildRangeFilter("id", LindenType.LONG, "1", "1", true, true), LindenBooleanClause.SHOULD);
    filterBuilder.addFilter(LindenRangeFilterBuilder.buildRangeFilter("id", LindenType.LONG, "2", "2", true, true), LindenBooleanClause.SHOULD);
    filterBuilder.addFilter(LindenRangeFilterBuilder.buildRangeFilter("id", LindenType.LONG, "3", "3", true, true), LindenBooleanClause.SHOULD);
    LindenFilter expected = filterBuilder.build();
    Assert.assertEquals(expected, lindenRequest.getFilter());
    bql = "select * from linden where id not in (1, 2, 3)";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    filterBuilder = new LindenBooleanFilterBuilder();
    filterBuilder.addFilter(LindenRangeFilterBuilder.buildRangeFilter("id", LindenType.LONG, "1", "1", true, true), LindenBooleanClause.MUST_NOT);
    filterBuilder.addFilter(LindenRangeFilterBuilder.buildRangeFilter("id", LindenType.LONG, "2", "2", true, true), LindenBooleanClause.MUST_NOT);
    filterBuilder.addFilter(LindenRangeFilterBuilder.buildRangeFilter("id", LindenType.LONG, "3", "3", true, true), LindenBooleanClause.MUST_NOT);
    expected = filterBuilder.build();
    Assert.assertEquals(expected, lindenRequest.getFilter());
    bql = "select * from linden where id in (1) except (2, 3)";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    filterBuilder = new LindenBooleanFilterBuilder();
    filterBuilder.addFilter(LindenRangeFilterBuilder.buildRangeFilter("id", LindenType.LONG, "1", "1", true, true), LindenBooleanClause.SHOULD);
    filterBuilder.addFilter(LindenRangeFilterBuilder.buildRangeFilter("id", LindenType.LONG, "2", "2", true, true), LindenBooleanClause.MUST_NOT);
    filterBuilder.addFilter(LindenRangeFilterBuilder.buildRangeFilter("id", LindenType.LONG, "3", "3", true, true), LindenBooleanClause.MUST_NOT);
    expected = filterBuilder.build();
    Assert.assertEquals(expected, lindenRequest.getFilter());
    bql = "select * from linden where dy.long in (1) except (2, 3)";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    filterBuilder = new LindenBooleanFilterBuilder();
    filterBuilder.addFilter(LindenRangeFilterBuilder.buildRangeFilter("dy", LindenType.LONG, "1", "1", true, true), LindenBooleanClause.SHOULD);
    filterBuilder.addFilter(LindenRangeFilterBuilder.buildRangeFilter("dy", LindenType.LONG, "2", "2", true, true), LindenBooleanClause.MUST_NOT);
    filterBuilder.addFilter(LindenRangeFilterBuilder.buildRangeFilter("dy", LindenType.LONG, "3", "3", true, true), LindenBooleanClause.MUST_NOT);
    expected = filterBuilder.build();
    Assert.assertEquals(expected, lindenRequest.getFilter());
    bql = "select * from linden by id in (1) except (2, 3)";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    LindenBooleanQueryBuilder queryBuilder = new LindenBooleanQueryBuilder();
    queryBuilder.addQuery(LindenRangeQueryBuilder.buildRangeQuery("id", LindenType.LONG, "1", "1", true, true), LindenBooleanClause.SHOULD);
    queryBuilder.addQuery(LindenRangeQueryBuilder.buildRangeQuery("id", LindenType.LONG, "2", "2", true, true), LindenBooleanClause.MUST_NOT);
    queryBuilder.addQuery(LindenRangeQueryBuilder.buildRangeQuery("id", LindenType.LONG, "3", "3", true, true), LindenBooleanClause.MUST_NOT);
    LindenQuery query = queryBuilder.build();
    Assert.assertEquals(query, lindenRequest.getQuery());
    bql = "select * from linden by id in ($a) except (2, $b)";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    queryBuilder = new LindenBooleanQueryBuilder();
    queryBuilder.addQuery(LindenRangeQueryBuilder.buildRangeQuery("id", LindenType.LONG, "2", "2", true, true), LindenBooleanClause.MUST_NOT);
    query = queryBuilder.build();
    Assert.assertEquals(query, lindenRequest.getQuery());
}
Also used : LindenFilter(com.xiaomi.linden.thrift.common.LindenFilter) LindenQuery(com.xiaomi.linden.thrift.common.LindenQuery) LindenBooleanFilterBuilder(com.xiaomi.linden.thrift.builder.filter.LindenBooleanFilterBuilder) LindenBooleanQueryBuilder(com.xiaomi.linden.thrift.builder.query.LindenBooleanQueryBuilder) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 15 with LindenSearchRequest

use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.

the class TestLindenAggregation method aggregationSearchTest.

@Test
public void aggregationSearchTest() throws IOException {
    String bql = "SELECT * FROM linden aggregate by intValue({*, *}, {*, -200], {-200, 0}, [0, 10}), " + "dValue.double({*, -5.0}, [-21.79, -0.9}, [-21.80, -0.9}, {1000, *], {0, 11.0])";
    LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals("[AggregationResult(field:intValue, labelValues:[LindenLabelAndValue(label:{*,*}, value:15), " + "LindenLabelAndValue(label:{*,-200], value:0), LindenLabelAndValue(label:{-200,0}, value:4), " + "LindenLabelAndValue(label:[0,10}, value:5)]), " + "AggregationResult(field:dValue, labelValues:[LindenLabelAndValue(label:{*,-5.0}, value:2), " + "LindenLabelAndValue(label:[-21.79,-0.9}, value:2), LindenLabelAndValue(label:[-21.80,-0.9}, value:3), " + "LindenLabelAndValue(label:{1000,*], value:0), LindenLabelAndValue(label:{0,11.0], value:6)])]", result.getAggregationResults().toString());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Aggregations

LindenSearchRequest (com.xiaomi.linden.thrift.common.LindenSearchRequest)95 Test (org.junit.Test)90 LindenResult (com.xiaomi.linden.thrift.common.LindenResult)69 LindenQuery (com.xiaomi.linden.thrift.common.LindenQuery)13 LindenFilter (com.xiaomi.linden.thrift.common.LindenFilter)9 LindenBooleanQueryBuilder (com.xiaomi.linden.thrift.builder.query.LindenBooleanQueryBuilder)5 LindenBooleanFilter (com.xiaomi.linden.thrift.common.LindenBooleanFilter)5 IOException (java.io.IOException)5 JSONObject (com.alibaba.fastjson.JSONObject)4 LindenBooleanSubFilter (com.xiaomi.linden.thrift.common.LindenBooleanSubFilter)4 LindenDeleteRequest (com.xiaomi.linden.thrift.common.LindenDeleteRequest)4 LindenScoreModel (com.xiaomi.linden.thrift.common.LindenScoreModel)4 Stopwatch (com.google.common.base.Stopwatch)3 MultiLindenCoreImpl (com.xiaomi.linden.core.search.MultiLindenCoreImpl)3 LindenFlexibleQueryBuilder (com.xiaomi.linden.thrift.builder.query.LindenFlexibleQueryBuilder)3 LindenFacet (com.xiaomi.linden.thrift.common.LindenFacet)3 LindenFacetDimAndPath (com.xiaomi.linden.thrift.common.LindenFacetDimAndPath)3 LindenFacetParam (com.xiaomi.linden.thrift.common.LindenFacetParam)3 LindenRequest (com.xiaomi.linden.thrift.common.LindenRequest)3 LindenTerm (com.xiaomi.linden.thrift.common.LindenTerm)3