use of com.xiaomi.linden.thrift.common.LindenFlexibleQuery in project linden by XiaoMi.
the class BQLCompilerAnalyzer method exitFlexible_query_predicate.
@Override
public void exitFlexible_query_predicate(BQLParser.Flexible_query_predicateContext ctx) {
String orig = unescapeStringLiteral(ctx.STRING_LITERAL());
LindenScoreModel lindenScoreModel = new LindenScoreModel().setName(ctx.IDENT().getText()).setFunc((String) valProperty.get(ctx.score_model())).setParams((List<LindenInputParam>) valProperty.get(ctx.formal_parameters()));
if (ctx.OVERRIDE() != null) {
lindenScoreModel.setOverride(true);
}
if (ctx.PLUGIN() != null) {
lindenScoreModel.setPlugin(true);
}
LindenFlexibleQuery lindenFlexibleQuery = new LindenFlexibleQuery().setQuery(orig).setFields((List<LindenSearchField>) valProperty.get(ctx.flexible_fields()));
lindenFlexibleQuery.setModel(lindenScoreModel);
if (ctx.fm != null) {
lindenFlexibleQuery.setFullMatch(true);
} else if (ctx.mrt != null && ctx.mrt.PLACEHOLDER() == null) {
double ratio = Double.valueOf(ctx.mrt.getText());
lindenFlexibleQuery.setMatchRatio(ratio);
}
LindenQuery lindenQuery = new LindenQuery();
if (inQueryWhere) {
if (ctx.gi != null) {
lindenFlexibleQuery.setGlobalIDF(true);
if (ctx.gfd != null) {
lindenFlexibleQuery.setGlobalFields((List<LindenSearchField>) valProperty.get(ctx.global_fields()));
}
}
queryProperty.put(ctx, lindenQuery.setFlexQuery(lindenFlexibleQuery));
} else {
filterProperty.put(ctx, LindenQueryFilterBuilder.buildQueryFilter(lindenQuery.setFlexQuery(lindenFlexibleQuery)));
}
}
use of com.xiaomi.linden.thrift.common.LindenFlexibleQuery in project linden by XiaoMi.
the class TestBQL method testFlexibleQuery.
@Test
public void testFlexibleQuery() {
String bql = "select * from linden by flexible_query is 'test' match 1 in (title, name^0.9)\n" + "using model test (Float a = 1, Long b = 2)\n" + "begin\n" + " return 1f;\n" + "end\n" + "where id = 231\n";
LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertTrue(lindenRequest.getQuery().isSetFlexQuery());
LindenFlexibleQuery lindenFlexibleQuery = new LindenFlexibleQuery().setQuery("test").setFields(Arrays.asList(new LindenSearchField("title"), new LindenSearchField("name").setBoost(0.9))).setModel(new LindenScoreModel().setName("test").setFunc("return 1f;").setParams(Arrays.asList(new LindenInputParam("a").setValue(new LindenValue().setDoubleValue(1)), new LindenInputParam("b").setValue(new LindenValue().setLongValue(2))))).setMatchRatio(1);
Assert.assertEquals(lindenFlexibleQuery, lindenRequest.getQuery().getFlexQuery());
// test full match
bql = "select * from linden by flexible_query is 'test' full_match in (title, name^0.9)\n" + "using model test (Float a = 1, Long b = 2)\n" + "begin\n" + " return 1f;\n" + "end\n" + "where id = 231\n";
lindenRequest = compiler.compile(bql).getSearchRequest();
Assert.assertTrue(lindenRequest.getQuery().isSetFlexQuery());
lindenFlexibleQuery = new LindenFlexibleQuery().setQuery("test").setFields(Arrays.asList(new LindenSearchField("title"), new LindenSearchField("name").setBoost(0.9))).setFullMatch(true).setModel(new LindenScoreModel().setName("test").setFunc("return 1f;").setParams(Arrays.asList(new LindenInputParam("a").setValue(new LindenValue().setDoubleValue(1)), new LindenInputParam("b").setValue(new LindenValue().setLongValue(2)))));
Assert.assertEquals(lindenFlexibleQuery, lindenRequest.getQuery().getFlexQuery());
}
use of com.xiaomi.linden.thrift.common.LindenFlexibleQuery in project linden by XiaoMi.
the class FlexibleQueryConstructor method construct.
@Override
protected Query construct(LindenQuery lindenQuery, LindenConfig config) throws IOException {
if (lindenQuery.isSetFlexQuery()) {
LindenFlexibleQuery lindenFlexibleQuery = lindenQuery.getFlexQuery();
List<FlexibleQuery.FlexibleField> fields = Lists.newArrayList();
for (LindenSearchField field : lindenFlexibleQuery.getFields()) {
fields.add(new FlexibleQuery.FlexibleField(field.getName(), field.getBoost()));
}
List<FlexibleQuery.FlexibleField> globalFields = initGlobalFields(lindenFlexibleQuery.isGlobalIDF(), lindenFlexibleQuery.getGlobalFields(), lindenFlexibleQuery.getFields());
FlexibleQuery flexibleQuery = new FlexibleQuery(fields, globalFields, lindenFlexibleQuery.getQuery(), lindenFlexibleQuery.getModel(), config);
flexibleQuery.setFullMatch(lindenFlexibleQuery.isFullMatch());
flexibleQuery.setGlobalIDF(lindenFlexibleQuery.isGlobalIDF());
flexibleQuery.setMatchRatio(lindenFlexibleQuery.getMatchRatio());
return flexibleQuery;
}
return null;
}
Aggregations