Search in sources :

Example 1 with GroupParam

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

the class TestLindenGroupSearch method groupSearchTest1.

@Test
public void groupSearchTest1() throws IOException {
    String function = "    float sum = 0;\n" + "    for (int i = 0; i < getFieldLength(); ++i) {\n" + "      for (int j = 0; j < getTermLength(); ++j) {\n" + "        sum += getScore(i, j) * rank();\n" + "      }\n" + "    }\n" + "    return sum;";
    LindenQuery query = new LindenFlexibleQueryBuilder().setQuery("lucene").addField("title").addModel("test", function).build();
    LindenSearchRequest request = new LindenSearchRequest().setQuery(query).setSource(false).setExplain(false);
    request.setGroupParam(new GroupParam("cat1").setGroupInnerLimit(2));
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals(true, result.isSuccess());
    Assert.assertEquals(5, result.getTotalHits());
    Assert.assertEquals(3, result.getTotalGroups());
    Assert.assertEquals(3, result.getHitsSize());
    Assert.assertEquals(2, result.getHits().get(0).getGroupHitsSize());
    Assert.assertEquals(1, result.getHits().get(1).getGroupHitsSize());
    Assert.assertEquals(2, result.getHits().get(2).getGroupHitsSize());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenFlexibleQueryBuilder(com.xiaomi.linden.thrift.builder.query.LindenFlexibleQueryBuilder) LindenQuery(com.xiaomi.linden.thrift.common.LindenQuery) GroupParam(com.xiaomi.linden.thrift.common.GroupParam) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 2 with GroupParam

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

the class BQLCompilerAnalyzer method exitSelect_stmt.

@Override
public void exitSelect_stmt(BQLParser.Select_stmtContext ctx) {
    if (ctx.order_by_clause().size() > 1) {
        throw new ParseCancellationException(new SemanticException(ctx.order_by_clause(1), "ORDER BY clause can only appear once."));
    }
    if (ctx.limit_clause().size() > 1) {
        throw new ParseCancellationException(new SemanticException(ctx.limit_clause(1), "LIMIT clause can only appear once."));
    }
    if (ctx.group_by_clause().size() > 1) {
        throw new ParseCancellationException(new SemanticException(ctx.group_by_clause(1), "GROUP BY clause can only appear once."));
    }
    if (ctx.browse_by_clause().size() > 1) {
        throw new ParseCancellationException(new SemanticException(ctx.browse_by_clause(1), "BROWSE BY clause can only appear once."));
    }
    if (ctx.drill_clause().size() > 1) {
        throw new ParseCancellationException(new SemanticException(ctx.drill_clause(1), "DRILL clause can only appear once."));
    }
    if (ctx.source_clause().size() > 1) {
        throw new ParseCancellationException(new SemanticException(ctx.source_clause(1), "SOURCE clause can only appear once."));
    }
    if (ctx.route_by_clause().size() > 1) {
        throw new ParseCancellationException(new SemanticException(ctx.route_by_clause(1), "ROUTE BY clause can only appear once."));
    }
    if (ctx.score_model_clause().size() > 1) {
        throw new ParseCancellationException(new SemanticException(ctx.score_model_clause(1), "USING SCORE MODEL clause can only appear once."));
    }
    LindenSearchRequest lindenRequest = new LindenSearchRequest();
    if (ctx.cols != null) {
        lindenRequest.setSourceFields((List<String>) valProperty.get(ctx.cols));
    }
    if (ctx.tables != null) {
        lindenRequest.setIndexNames((List<String>) valProperty.get(ctx.tables));
    }
    if (ctx.group_by != null) {
        GroupParam groupParam = (GroupParam) valProperty.get(ctx.group_by);
        if (groupParam != null) {
            lindenRequest.setGroupParam(groupParam);
        }
    }
    if (ctx.limit != null) {
        lindenRequest.setOffset(offsetProperty.get(ctx.limit));
        lindenRequest.setLength(countProperty.get(ctx.limit));
    }
    if (ctx.source != null && (Boolean) valProperty.get(ctx.source)) {
        lindenRequest.setSource(true);
    }
    if (ctx.explain != null && (Boolean) valProperty.get(ctx.explain)) {
        lindenRequest.setExplain(true);
    }
    LindenQuery query = null;
    if (ctx.q != null) {
        query = queryProperty.get(ctx.q);
    }
    if (query == null) {
        query = LindenQueryBuilder.buildMatchAllQuery();
    }
    lindenRequest.setQuery(query);
    if (ctx.w != null) {
        LindenFilter filter = filterProperty.get(ctx.w);
        lindenRequest.setFilter(filter);
    }
    if (ctx.scoring_model != null) {
        LindenScoreModel scoreModel = (LindenScoreModel) valProperty.get(ctx.scoring_model);
        lindenRequest.getQuery().setScoreModel(scoreModel);
    }
    if (ctx.boost_by != null && ctx.boost_by.numeric_value().PLACEHOLDER() == null) {
        lindenRequest.getQuery().setBoost(Double.valueOf(ctx.boost_by.numeric_value().getText()));
    }
    if (spatialParam != null) {
        lindenRequest.setSpatialParam(spatialParam);
    }
    if (ctx.order_by != null) {
        lindenRequest.setSort((LindenSort) valProperty.get(ctx.order_by));
    }
    if (ctx.snippet != null) {
        lindenRequest.setSnippetParam((SnippetParam) valProperty.get(ctx.snippet));
    }
    if (ctx.in_top != null) {
        lindenRequest.setEarlyParam((EarlyParam) valProperty.get(ctx.in_top));
    }
    if (ctx.route_param != null) {
        lindenRequest.setRouteParam((SearchRouteParam) valProperty.get(ctx.route_param));
    }
    if (facetRequest.isSetFacetParams() || facetRequest.isSetDrillDownDimAndPaths() || facetRequest.isSetAggregations()) {
        lindenRequest.setFacet(facetRequest);
    }
    lindenSearchRequestProperty.put(ctx, lindenRequest);
}
Also used : LindenFilter(com.xiaomi.linden.thrift.common.LindenFilter) LindenQuery(com.xiaomi.linden.thrift.common.LindenQuery) ParseCancellationException(org.antlr.v4.runtime.misc.ParseCancellationException) GroupParam(com.xiaomi.linden.thrift.common.GroupParam) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) LindenScoreModel(com.xiaomi.linden.thrift.common.LindenScoreModel)

Example 3 with GroupParam

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

the class BQLCompilerAnalyzer method exitGroup_by_clause.

@Override
public void exitGroup_by_clause(BQLParser.Group_by_clauseContext ctx) {
    String col = unescapeColumnName(ctx.column_name());
    Map.Entry<String, LindenType> fieldNameAndType = getFieldNameAndType(col);
    col = fieldNameAndType.getKey();
    GroupParam groupParam = new GroupParam(col);
    if (ctx.top != null && ctx.PLACEHOLDER() == null) {
        groupParam.setGroupInnerLimit(Integer.valueOf(ctx.top.getText()));
    }
    valProperty.put(ctx, groupParam);
}
Also used : LindenType(com.xiaomi.linden.thrift.common.LindenType) GroupParam(com.xiaomi.linden.thrift.common.GroupParam) Map(java.util.Map) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap)

Aggregations

GroupParam (com.xiaomi.linden.thrift.common.GroupParam)3 LindenQuery (com.xiaomi.linden.thrift.common.LindenQuery)2 LindenSearchRequest (com.xiaomi.linden.thrift.common.LindenSearchRequest)2 LindenFlexibleQueryBuilder (com.xiaomi.linden.thrift.builder.query.LindenFlexibleQueryBuilder)1 LindenFilter (com.xiaomi.linden.thrift.common.LindenFilter)1 LindenResult (com.xiaomi.linden.thrift.common.LindenResult)1 LindenScoreModel (com.xiaomi.linden.thrift.common.LindenScoreModel)1 LindenType (com.xiaomi.linden.thrift.common.LindenType)1 AbstractMap (java.util.AbstractMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ParseCancellationException (org.antlr.v4.runtime.misc.ParseCancellationException)1 Test (org.junit.Test)1