use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.
the class TestBQL method testEqualPredicate.
@Test
public void testEqualPredicate() {
String bql = "select * from linden where title = \"qq\" and id = 211 limit 10, 50";
LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertTrue(lindenRequest.getFilter().isSetBooleanFilter());
LindenBooleanFilter booleanFilter = lindenRequest.getFilter().getBooleanFilter();
Assert.assertEquals(2, booleanFilter.getFiltersSize());
Assert.assertEquals(LindenBooleanClause.MUST, booleanFilter.getFilters().get(0).getClause());
Assert.assertEquals(new LindenTerm("title", "qq"), booleanFilter.getFilters().get(0).getFilter().getTermFilter().getTerm());
Assert.assertEquals(LindenBooleanClause.MUST, booleanFilter.getFilters().get(1).getClause());
Assert.assertEquals(new LindenRange("id", LindenType.LONG, true, true).setStartValue("211").setEndValue("211"), booleanFilter.getFilters().get(1).getFilter().getRangeFilter().getRange());
Assert.assertEquals(10, lindenRequest.getOffset());
Assert.assertEquals(50, lindenRequest.getLength());
bql = "delete from default where title = \"q\"\"q\" and id = 211";
LindenDeleteRequest deleteRequest = compiler.compile(bql).getDeleteRequest();
Assert.assertTrue(deleteRequest.getQuery().isSetFilteredQuery());
Assert.assertTrue(deleteRequest.getQuery().getFilteredQuery().isSetLindenFilter());
Assert.assertTrue(deleteRequest.getQuery().getFilteredQuery().getLindenFilter().isSetBooleanFilter());
booleanFilter = deleteRequest.getQuery().getFilteredQuery().getLindenFilter().getBooleanFilter();
Assert.assertEquals(2, booleanFilter.getFiltersSize());
Assert.assertEquals(LindenBooleanClause.MUST, booleanFilter.getFilters().get(0).getClause());
Assert.assertEquals(new LindenTerm("title", "q\"q"), booleanFilter.getFilters().get(0).getFilter().getTermFilter().getTerm());
Assert.assertEquals(LindenBooleanClause.MUST, booleanFilter.getFilters().get(1).getClause());
Assert.assertEquals(new LindenRange("id", LindenType.LONG, true, true).setStartValue("211").setEndValue("211"), booleanFilter.getFilters().get(1).getFilter().getRangeFilter().getRange());
bql = "delete from default where title = $a and id = 211";
deleteRequest = compiler.compile(bql).getDeleteRequest();
Assert.assertTrue(deleteRequest.getQuery().isSetFilteredQuery());
Assert.assertTrue(deleteRequest.getQuery().getFilteredQuery().isSetLindenFilter());
Assert.assertTrue(deleteRequest.getQuery().getFilteredQuery().getLindenFilter().isSetRangeFilter());
bql = "select * from linden where dynmaicTitle.STRING = \"qq\" and dynamicId.int = 211 limit 10, 50";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertTrue(lindenRequest.getFilter().isSetBooleanFilter());
booleanFilter = lindenRequest.getFilter().getBooleanFilter();
Assert.assertEquals(2, booleanFilter.getFiltersSize());
Assert.assertEquals(LindenBooleanClause.MUST, booleanFilter.getFilters().get(0).getClause());
Assert.assertEquals(new LindenTerm("dynmaicTitle", "qq"), booleanFilter.getFilters().get(0).getFilter().getTermFilter().getTerm());
Assert.assertEquals(LindenBooleanClause.MUST, booleanFilter.getFilters().get(1).getClause());
Assert.assertEquals(new LindenRange("dynamicId", LindenType.INTEGER, true, true).setStartValue("211").setEndValue("211"), booleanFilter.getFilters().get(1).getFilter().getRangeFilter().getRange());
Assert.assertEquals(10, lindenRequest.getOffset());
Assert.assertEquals(50, lindenRequest.getLength());
bql = "select * from linden by title = \"qq\" subBoost by 0.5 and id = 211 andDisableCoord limit 10, 50";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertFalse(lindenRequest.isSetFilter());
Assert.assertTrue(lindenRequest.getQuery().isSetBooleanQuery());
LindenBooleanQuery query = lindenRequest.getQuery().getBooleanQuery();
Assert.assertTrue(query.isDisableCoord());
Assert.assertEquals(2, query.getQueriesSize());
Assert.assertEquals(LindenBooleanClause.MUST, query.getQueries().get(0).clause);
Assert.assertEquals(new LindenTerm("title", "qq"), query.getQueries().get(0).getQuery().getTermQuery().getTerm());
Assert.assertEquals(0.5, query.getQueries().get(0).getQuery().getBoost(), 0.001);
Assert.assertEquals(LindenBooleanClause.MUST, query.getQueries().get(1).clause);
Assert.assertEquals(new LindenRange("id", LindenType.LONG, true, true).setStartValue("211").setEndValue("211"), query.getQueries().get(1).getQuery().getRangeQuery().getRange());
Assert.assertEquals(10, lindenRequest.getOffset());
Assert.assertEquals(50, lindenRequest.getLength());
}
use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.
the class TestBQL method testFacetBrowsing.
@Test
public void testFacetBrowsing() {
String bql = "SELECT title, rank FROM linden browse by 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.addToFacetParams(new LindenFacetParam().setFacetDimAndPath(new LindenFacetDimAndPath().setDim("color")));
Assert.assertEquals(facetRequest, lindenRequest.getFacet());
bql = "SELECT * FROM linden browse by color(5)";
lindenRequest = compiler.compile(bql).getSearchRequest();
facetRequest = new LindenFacet();
facetRequest.addToFacetParams(new LindenFacetParam().setTopN(5).setFacetDimAndPath(new LindenFacetDimAndPath().setDim("color")));
Assert.assertEquals(facetRequest, lindenRequest.getFacet());
bql = "SELECT * FROM linden browse by color(6, \"red\")";
lindenRequest = compiler.compile(bql).getSearchRequest();
facetRequest = new LindenFacet();
facetRequest.addToFacetParams(new LindenFacetParam().setTopN(6).setFacetDimAndPath(new LindenFacetDimAndPath().setDim("color").setPath("red")));
Assert.assertEquals(facetRequest, lindenRequest.getFacet());
bql = "SELECT * FROM linden browse by color(6, 'light/gray/white')";
lindenRequest = compiler.compile(bql).getSearchRequest();
facetRequest = new LindenFacet();
facetRequest.addToFacetParams(new LindenFacetParam().setTopN(6).setFacetDimAndPath(new LindenFacetDimAndPath().setDim("color").setPath("light/gray/white")));
Assert.assertEquals(facetRequest, lindenRequest.getFacet());
bql = "SELECT * FROM linden browse by color(6, 'light/gray/white'), color(5, 'red'), shape(10, '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.addToFacetParams(new LindenFacetParam().setTopN(5).setFacetDimAndPath(new LindenFacetDimAndPath().setDim("color").setPath("red")));
facetRequest.addToFacetParams(new LindenFacetParam().setTopN(10).setFacetDimAndPath(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 TestLindenCore method flexibleQueryTest.
@Test
public void flexibleQueryTest() 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 += 100 * getScore(i, j) * rank();\n" + " }\n" + " }\n" + " return sum;";
LindenQuery flexQuery = new LindenFlexibleQueryBuilder().setQuery("lucene").addField("title").addModel("test", function).build();
LindenResult result = lindenCore.search(new LindenSearchRequest().setQuery(flexQuery));
Assert.assertEquals(4, result.getTotalHits());
flexQuery = new LindenFlexibleQueryBuilder().setQuery("lucene 1").addField("title").addModel("test", function).setFullMatch(true).build();
result = lindenCore.search(new LindenSearchRequest().setQuery(flexQuery));
Assert.assertEquals(1, result.getTotalHits());
}
use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.
the class TestLindenCore method testScoreModelPlugin.
@Test
public void testScoreModelPlugin() throws IOException {
String bql = "select * from linden where title='lucene'" + " using score model plugin com.xiaomi.linden.core.plugin.TestScoreModelStrategy" + "(Long param1 = $long1, Map<String, Double> dict = {'中文': 1.0, 'b': 2.0});";
LindenSearchRequest searchRequest = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(searchRequest);
Assert.assertEquals(4, result.getTotalHits());
Assert.assertEquals(14.3, result.getHits().get(0).getScore(), 0.01);
}
use of com.xiaomi.linden.thrift.common.LindenSearchRequest in project linden by XiaoMi.
the class TestLindenCore method likeTest.
@Test
public void likeTest() throws Exception {
String bql = "select * from linden by field1 like \"aa*\" source boost by 2";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
Query query = QueryConstructor.constructQuery(request.getQuery(), lindenConfig);
Assert.assertTrue(query instanceof WildcardQuery);
Assert.assertEquals("field1:aa*^2.0", query.toString());
LindenResult result = lindenCore.search(request);
Assert.assertEquals(1, result.getTotalHits());
bql = "select * from linden by field1 not like \"aaa*\" source";
request = bqlCompiler.compile(bql).getSearchRequest();
query = QueryConstructor.constructQuery(request.getQuery(), lindenConfig);
Assert.assertTrue(query instanceof BooleanQuery);
Assert.assertEquals("+*:* -field1:aaa*", query.toString());
result = lindenCore.search(request);
Assert.assertEquals(5, result.getTotalHits());
}
Aggregations