use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.
the class TestHadoopIndexingInOneBox method searchTest.
@Test
public void searchTest() throws Exception {
System.out.println("Start basicTest");
LindenSearchRequest request = new LindenSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals(15000, result.getTotalHits());
request = bqlCompiler.compile("select * from linden where color='green'").getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(1084, result.getTotalHits());
request = bqlCompiler.compile("select * from linden where price=7000").getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(148, result.getTotalHits());
request = bqlCompiler.compile("select * from linden by query is \"contents:(compact AND green)\"").getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(589, result.getTotalHits());
Assert.assertEquals(1.0581597089767456, result.getHits().get(0).getScore(), 1e-16);
request = bqlCompiler.compile("select * from linden browse by color(3), makemodel drill sideways makemodel('european/audi') source").getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(2, result.getFacetResults().size());
Assert.assertEquals(403, result.getFacetResults().get(0).getValue());
Assert.assertEquals(8, result.getFacetResults().get(0).getChildCount());
Assert.assertEquals("black", result.getFacetResults().get(0).getLabelValues().get(0).getLabel());
Assert.assertEquals(131, result.getFacetResults().get(0).getLabelValues().get(0).getValue());
Assert.assertEquals(15000, result.getFacetResults().get(1).getValue());
Assert.assertEquals(3, result.getFacetResults().get(1).getChildCount());
Assert.assertEquals("asian", result.getFacetResults().get(1).getLabelValues().get(0).getLabel());
Assert.assertEquals(5470, result.getFacetResults().get(1).getLabelValues().get(0).getValue());
lindenCore.close();
}
use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.
the class TestBQL method testBoostBy.
@Test
public void testBoostBy() {
String bql = "select * from linden where title = 'qq' and id = 211 boost by 0.5";
LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertEquals(0.5, lindenRequest.getQuery().getBoost(), 0.001);
bql = "select * from linden by title = 'test' subBoost by 0.8 and id = 211 subBoost by 2 boost by 0.5";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertEquals(0.5, lindenRequest.getQuery().getBoost(), 0.001);
Assert.assertEquals(0.8, lindenRequest.getQuery().getBooleanQuery().getQueries().get(0).getQuery().getBoost(), 0.001);
Assert.assertEquals(2, lindenRequest.getQuery().getBooleanQuery().getQueries().get(1).getQuery().getBoost(), 0.001);
bql = "select * from linden by title = 'test' subBoost by $b1 and id = 211 subBoost by 2 boost by $b2";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertEquals(1, lindenRequest.getQuery().getBoost(), 0.001);
Assert.assertEquals(1, lindenRequest.getQuery().getBooleanQuery().getQueries().get(0).getQuery().getBoost(), 0.001);
Assert.assertEquals(2, lindenRequest.getQuery().getBooleanQuery().getQueries().get(1).getQuery().getBoost(), 0.001);
bql = "select * from linden by title = 'test' subBoost by 0.8 and id in (200, 201) subBoost by 2";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertEquals(0.8, lindenRequest.getQuery().getBooleanQuery().getQueries().get(0).getQuery().getBoost(), 0.001);
Assert.assertEquals(2, lindenRequest.getQuery().getBooleanQuery().getQueries().get(1).getQuery().getBoost(), 0.001);
bql = "select * from linden by title = 'test' subBoost by 0.8 and id = 211 subBoost by 2 andBoost by 3 or query is 'content:test' subBoost by 5 boost by 0.5";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertEquals(0.5, lindenRequest.getQuery().getBoost(), 0.001);
Assert.assertEquals(3, lindenRequest.getQuery().getBooleanQuery().getQueries().get(0).getQuery().getBoost(), 0.001);
Assert.assertEquals(0.8, lindenRequest.getQuery().getBooleanQuery().getQueries().get(0).getQuery().getBooleanQuery().getQueries().get(0).getQuery().getBoost(), 0.001);
Assert.assertEquals(2, lindenRequest.getQuery().getBooleanQuery().getQueries().get(0).getQuery().getBooleanQuery().getQueries().get(1).getQuery().getBoost(), 0.001);
Assert.assertEquals(5, lindenRequest.getQuery().getBooleanQuery().getQueries().get(1).getQuery().getBoost(), 0.001);
bql = "select * from linden by title = 'test' subBoost by 0.8 and (id = 211 subBoost by 2 or query is 'content:test' subBoost by 5 orBoost by 3)";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertEquals(1, lindenRequest.getQuery().getBoost(), 0.001);
Assert.assertEquals(0.8, lindenRequest.getQuery().getBooleanQuery().getQueries().get(0).getQuery().getBoost(), 0.001);
Assert.assertEquals(3, lindenRequest.getQuery().getBooleanQuery().getQueries().get(1).getQuery().getBoost(), 0.001);
Assert.assertEquals(2, lindenRequest.getQuery().getBooleanQuery().getQueries().get(1).getQuery().getBooleanQuery().getQueries().get(0).getQuery().getBoost(), 0.001);
Assert.assertEquals(5, lindenRequest.getQuery().getBooleanQuery().getQueries().get(1).getQuery().getBooleanQuery().getQueries().get(1).getQuery().getBoost(), 0.001);
bql = "select * from linden by (title = 'test' subBoost by 0.8 and query is 'body:test' andBoost by 6) and (id = 211 subBoost by 2 or query is 'content:test' subBoost by 5 orBoost by 3)";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertEquals(1, lindenRequest.getQuery().getBoost(), 0.001);
Assert.assertEquals(6, lindenRequest.getQuery().getBooleanQuery().getQueries().get(0).getQuery().getBoost(), 0.001);
Assert.assertEquals(0.8, lindenRequest.getQuery().getBooleanQuery().getQueries().get(0).getQuery().getBooleanQuery().getQueries().get(0).getQuery().getBoost(), 0.001);
Assert.assertEquals(1, lindenRequest.getQuery().getBooleanQuery().getQueries().get(0).getQuery().getBooleanQuery().getQueries().get(1).getQuery().getBoost(), 0.001);
Assert.assertEquals(3, lindenRequest.getQuery().getBooleanQuery().getQueries().get(1).getQuery().getBoost(), 0.001);
Assert.assertEquals(2, lindenRequest.getQuery().getBooleanQuery().getQueries().get(1).getQuery().getBooleanQuery().getQueries().get(0).getQuery().getBoost(), 0.001);
Assert.assertEquals(5, lindenRequest.getQuery().getBooleanQuery().getQueries().get(1).getQuery().getBooleanQuery().getQueries().get(1).getQuery().getBoost(), 0.001);
}
use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.
the class TestBQL method testInTop.
@Test
public void testInTop() {
String bql = "SELECT * FROM linden where title = 'sed' in top 500";
LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
EarlyParam earlyParam = new EarlyParam();
earlyParam.setMaxNum(500);
Assert.assertEquals(earlyParam, lindenRequest.getEarlyParam());
bql = "SELECT * FROM linden where title = 'sed' in top $num";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertFalse(lindenRequest.isSetEarlyParam());
bql = "SELECT * FROM linden where title = 'sed' route by (0, 1, 2) in top 500, 3, replica_key '123'";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertFalse(lindenRequest.isSetEarlyParam());
Assert.assertEquals(4, lindenRequest.getRouteParam().getShardParamsSize());
Assert.assertEquals(earlyParam, lindenRequest.getRouteParam().getShardParams().get(0).getEarlyParam());
Assert.assertEquals(0, lindenRequest.getRouteParam().getShardParams().get(0).getShardId());
Assert.assertEquals(earlyParam, lindenRequest.getRouteParam().getShardParams().get(1).getEarlyParam());
Assert.assertEquals(1, lindenRequest.getRouteParam().getShardParams().get(1).getShardId());
Assert.assertEquals(earlyParam, lindenRequest.getRouteParam().getShardParams().get(2).getEarlyParam());
Assert.assertEquals(2, lindenRequest.getRouteParam().getShardParams().get(2).getShardId());
Assert.assertFalse(lindenRequest.getRouteParam().getShardParams().get(3).isSetEarlyParam());
Assert.assertEquals(3, lindenRequest.getRouteParam().getShardParams().get(3).getShardId());
Assert.assertEquals("123", lindenRequest.getRouteParam().getReplicaRouteKey());
}
use of com.xiaomi.linden.thrift.common.LindenSearchRequest 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.LindenSearchRequest in project linden by XiaoMi.
the class TestBQL method testIgnoreClause.
@Test
public void testIgnoreClause() {
String bql = "select * from linden where title = $a or id = 211";
LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertTrue(lindenRequest.getFilter().isSetRangeFilter());
bql = "select * from linden where title = $b and id = 211";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertTrue(lindenRequest.getFilter().isSetRangeFilter());
bql = "select * from linden where title = \"test\" and id = $id";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertTrue(lindenRequest.getFilter().isSetTermFilter());
// distance ignore
bql = "select * from linden where title = \"ignore\" or (distance($a, $b) in 1 and id = $c)";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertTrue(lindenRequest.getFilter().isSetTermFilter());
// limit ignore
bql = "select * from linden where title = \"lucene\" limit $from, $size";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertTrue(lindenRequest.getFilter().isSetTermFilter());
// explain ignore
bql = "select * from linden where title = \"lucene\" explain $e";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertFalse(lindenRequest.isExplain());
// source ignore
bql = "select * from linden where title = \"lucene\" source $a";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertFalse(lindenRequest.isSource());
}
Aggregations