Search in sources :

Example 1 with LindenSearchRequest

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

the class TestBQL method testSpatialFilter.

@Test
public void testSpatialFilter() throws InterruptedException {
    String bql = "select * from linden where distance(116.7, 35.3) in 10";
    LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
    LindenFilter spatialFilter = LindenSpatialFilterBuilder.buildSpatialParam(35.3, 116.7, 10);
    Assert.assertEquals(spatialFilter, lindenRequest.getFilter());
}
Also used : LindenFilter(com.xiaomi.linden.thrift.common.LindenFilter) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 2 with LindenSearchRequest

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

the class TestBQL method testScoreModel.

@Test
public void testScoreModel() {
    String bql = "select * from linden where title = 'qq' " + "using score model test (Float link = 1)" + "   begin" + "     return score();" + "   end";
    LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
    Assert.assertEquals(new LindenTerm("title", "qq"), lindenRequest.getFilter().getTermFilter().getTerm());
    LindenScoreModel lindenScoreModel = new LindenScoreModel().setName("test").setFunc("return score();");
    lindenScoreModel.addToParams(new LindenInputParam("link").setValue(new LindenValue().setDoubleValue(1)));
    Assert.assertTrue(lindenRequest.getQuery().isSetMatchAllQuery());
    Assert.assertEquals(lindenScoreModel, lindenRequest.getQuery().getScoreModel());
    bql = "select * from linden where title = 'qq' " + "using score model override test (Float link = 1)" + "   begin" + "     return score();" + "   end";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    Assert.assertEquals(new LindenTerm("title", "qq"), lindenRequest.getFilter().getTermFilter().getTerm());
    lindenScoreModel = new LindenScoreModel().setName("test").setFunc("return score();").setOverride(true);
    lindenScoreModel.addToParams(new LindenInputParam("link").setValue(new LindenValue().setDoubleValue(1)));
    Assert.assertTrue(lindenRequest.getQuery().isSetMatchAllQuery());
    Assert.assertEquals(lindenScoreModel, lindenRequest.getQuery().getScoreModel());
    // list input params.
    bql = "select * from linden where title = 'qq' " + "using score model test (Float link = [1, 2], Integer pos = [3, 4], Map<String,Double> kv = {\"a\":1, \"b\":2})" + "   begin" + "     return score();" + "   end";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    lindenScoreModel = new LindenScoreModel().setName("test").setFunc("return score();");
    LindenInputParam inputParam = new LindenInputParam("link").setValue(new LindenValue());
    inputParam.getValue().addToDoubleValues(1);
    inputParam.getValue().addToDoubleValues(2);
    lindenScoreModel.addToParams(inputParam);
    LindenInputParam inputParam2 = new LindenInputParam("pos").setValue(new LindenValue());
    inputParam2.getValue().addToLongValues(3);
    inputParam2.getValue().addToLongValues(4);
    lindenScoreModel.addToParams(inputParam2);
    LindenInputParam inputParam3 = new LindenInputParam("kv").setValue(new LindenValue());
    inputParam3.getValue().putToMapValue(new LindenValue().setStringValue("a"), new LindenValue().setDoubleValue(1));
    inputParam3.getValue().putToMapValue(new LindenValue().setStringValue("b"), new LindenValue().setDoubleValue(2));
    lindenScoreModel.addToParams(inputParam3);
    Assert.assertEquals(lindenScoreModel, lindenRequest.getQuery().getScoreModel());
}
Also used : LindenInputParam(com.xiaomi.linden.thrift.common.LindenInputParam) LindenValue(com.xiaomi.linden.thrift.common.LindenValue) LindenTerm(com.xiaomi.linden.thrift.common.LindenTerm) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) LindenScoreModel(com.xiaomi.linden.thrift.common.LindenScoreModel) Test(org.junit.Test)

Example 3 with LindenSearchRequest

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

the class TestBQL method testRoute.

@Test
public void testRoute() {
    String bql = "SELECT * FROM linden where title = 'sed' route by 0, 1, 2, replica_key '12345'";
    LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
    SearchRouteParam routeParam = new SearchRouteParam();
    routeParam.addToShardParams(new ShardRouteParam(0));
    routeParam.addToShardParams(new ShardRouteParam(1));
    routeParam.addToShardParams(new ShardRouteParam(2));
    routeParam.setReplicaRouteKey("12345");
    Assert.assertEquals(routeParam, lindenRequest.getRouteParam());
    bql = "SELECT * FROM linden where title = 'sed' route by 0 in top 500, 1, 2, $a, $shard in top 500, 3 in top $max";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    routeParam = new SearchRouteParam();
    routeParam.addToShardParams(new ShardRouteParam(0).setEarlyParam(new EarlyParam(500)));
    routeParam.addToShardParams(new ShardRouteParam(1));
    routeParam.addToShardParams(new ShardRouteParam(2));
    routeParam.addToShardParams(new ShardRouteParam(3));
    Assert.assertEquals(routeParam, lindenRequest.getRouteParam());
    bql = "SELECT * FROM linden where title = 'sed' route by (0,1) in top 10000, ($shard) in top 1000, 2";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    routeParam = new SearchRouteParam();
    routeParam.addToShardParams(new ShardRouteParam(0).setEarlyParam(new EarlyParam().setMaxNum(10000)));
    routeParam.addToShardParams(new ShardRouteParam(1).setEarlyParam(new EarlyParam().setMaxNum(10000)));
    routeParam.addToShardParams(new ShardRouteParam(2));
    Assert.assertEquals(routeParam, lindenRequest.getRouteParam());
}
Also used : ShardRouteParam(com.xiaomi.linden.thrift.common.ShardRouteParam) EarlyParam(com.xiaomi.linden.thrift.common.EarlyParam) SearchRouteParam(com.xiaomi.linden.thrift.common.SearchRouteParam) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 4 with LindenSearchRequest

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

the class TestBQL method testFacetDrilling.

@Test
public void testFacetDrilling() {
    String bql = "SELECT title, rank FROM linden drill down color";
    LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
    Assert.assertEquals("title", lindenRequest.getSourceFields().get(0));
    Assert.assertEquals("rank", lindenRequest.getSourceFields().get(1));
    LindenFacet facetRequest = new LindenFacet();
    facetRequest.addToDrillDownDimAndPaths(new LindenFacetDimAndPath().setDim("color"));
    Assert.assertEquals(facetRequest, lindenRequest.getFacet());
    bql = "SELECT * FROM linden browse by color(5) drill sideways shape('rectangle')";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    facetRequest = new LindenFacet();
    facetRequest.setFacetDrillingType(FacetDrillingType.DRILLSIDEWAYS);
    facetRequest.addToFacetParams(new LindenFacetParam().setTopN(5).setFacetDimAndPath(new LindenFacetDimAndPath().setDim("color")));
    facetRequest.addToDrillDownDimAndPaths(new LindenFacetDimAndPath().setDim("shape").setPath("rectangle"));
    Assert.assertEquals(facetRequest, lindenRequest.getFacet());
    bql = "SELECT * FROM linden drill down color(\"red\")";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    facetRequest = new LindenFacet();
    facetRequest.addToDrillDownDimAndPaths(new LindenFacetDimAndPath().setDim("color").setPath("red"));
    Assert.assertEquals(facetRequest, lindenRequest.getFacet());
    bql = "SELECT * FROM linden drill sideways color('light/gray/white') ";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    facetRequest = new LindenFacet();
    facetRequest.setFacetDrillingType(FacetDrillingType.DRILLSIDEWAYS);
    facetRequest.addToDrillDownDimAndPaths(new LindenFacetDimAndPath().setDim("color").setPath("light/gray/white"));
    Assert.assertEquals(facetRequest, lindenRequest.getFacet());
    bql = "SELECT * FROM linden browse by color(6, 'light/gray/white') drill down color('red'), shape('rectangle')";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    facetRequest = new LindenFacet();
    facetRequest.addToFacetParams(new LindenFacetParam().setTopN(6).setFacetDimAndPath(new LindenFacetDimAndPath().setDim("color").setPath("light/gray/white")));
    facetRequest.addToDrillDownDimAndPaths(new LindenFacetDimAndPath().setDim("color").setPath("red"));
    facetRequest.addToDrillDownDimAndPaths(new LindenFacetDimAndPath().setDim("shape").setPath("rectangle"));
    Assert.assertEquals(facetRequest, lindenRequest.getFacet());
}
Also used : LindenFacetDimAndPath(com.xiaomi.linden.thrift.common.LindenFacetDimAndPath) LindenFacetParam(com.xiaomi.linden.thrift.common.LindenFacetParam) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) LindenFacet(com.xiaomi.linden.thrift.common.LindenFacet) Test(org.junit.Test)

Example 5 with LindenSearchRequest

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

the class TestBQL method testRangePred.

@Test
public void testRangePred() throws Exception {
    String bql = "SELECT * FROM linden WHERE id > 1999";
    LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
    LindenFilter expectedFilter = LindenRangeFilterBuilder.buildRangeFilter("id", LindenType.LONG, "1999", null, false, false);
    Assert.assertEquals(expectedFilter, lindenRequest.getFilter());
    bql = "SELECT * FROM linden  WHERE id <= 2000";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    expectedFilter = LindenRangeFilterBuilder.buildRangeFilter("id", LindenType.LONG, null, "2000", false, true);
    Assert.assertEquals(expectedFilter, lindenRequest.getFilter());
    bql = "SELECT * FROM linden WHERE id <= $e";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    Assert.assertEquals(null, lindenRequest.getFilter());
    bql = "SELECT * FROM linden by id <= 2000";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    LindenQuery query = LindenRangeQueryBuilder.buildRangeQuery("id", LindenType.LONG, null, "2000", false, true);
    Assert.assertEquals(query, lindenRequest.getQuery());
    bql = "SELECT * FROM linden by id <= 2000 and id > 1000 subBoost by 0.5";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    LindenQuery query1 = LindenRangeQueryBuilder.buildRangeQuery("id", LindenType.LONG, null, "2000", false, true);
    LindenQuery query2 = LindenRangeQueryBuilder.buildRangeQuery("id", LindenType.LONG, "1000", null, false, false);
    query2.setBoost(0.5);
    LindenBooleanQueryBuilder builder = new LindenBooleanQueryBuilder();
    builder.addQuery(query1, LindenBooleanClause.MUST);
    builder.addQuery(query2, LindenBooleanClause.MUST);
    Assert.assertEquals(builder.build(), lindenRequest.getQuery());
    bql = "SELECT * FROM linden WHERE color > 're''d'";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    expectedFilter = LindenRangeFilterBuilder.buildRangeFilter("color", LindenType.FACET, "re'd", null, false, false);
    Assert.assertEquals(expectedFilter, lindenRequest.getFilter());
}
Also used : LindenFilter(com.xiaomi.linden.thrift.common.LindenFilter) LindenQuery(com.xiaomi.linden.thrift.common.LindenQuery) LindenBooleanQueryBuilder(com.xiaomi.linden.thrift.builder.query.LindenBooleanQueryBuilder) 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