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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations