use of com.xiaomi.linden.thrift.common.LindenQuery in project linden by XiaoMi.
the class TestLindenCore method flexibleQueryEmptyFieldTest.
@Test
public void flexibleQueryEmptyFieldTest() throws IOException {
String function = " if (tagnum() != 0) {\n" + " return 10f;\n" + " } else if (tagstr().length > 0) {\n" + " return 100f;\n" + " } else {\n" + " return 1f;\n" + " }";
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());
Assert.assertEquals("3", result.getHits().get(0).getId());
Assert.assertEquals(100f, result.getHits().get(0).getScore(), 0.01);
Assert.assertEquals("2", result.getHits().get(1).getId());
Assert.assertEquals(10f, result.getHits().get(1).getScore(), 0.01);
}
use of com.xiaomi.linden.thrift.common.LindenQuery in project linden by XiaoMi.
the class DisMaxQueryConstructor method construct.
@Override
protected Query construct(LindenQuery lindenQuery, LindenConfig config) throws Exception {
if (!lindenQuery.isSetDisMaxQuery()) {
return null;
}
LindenDisMaxQuery disMaxQuery = lindenQuery.getDisMaxQuery();
DisjunctionMaxQuery disjunctionMaxQuery = new DisjunctionMaxQuery((float) disMaxQuery.getTie());
for (LindenQuery subLindenQuery : disMaxQuery.getQueries()) {
Query query = QueryConstructor.constructQuery(subLindenQuery, config);
if (query != null) {
disjunctionMaxQuery.add(query);
}
}
return disjunctionMaxQuery;
}
use of com.xiaomi.linden.thrift.common.LindenQuery in project linden by XiaoMi.
the class QueryStringQueryConstructor method construct.
@Override
protected Query construct(LindenQuery lindenQuery, LindenConfig config) throws IOException {
LindenQueryStringQuery stringQuery = lindenQuery.getQueryString();
QueryParser.Operator op = QueryParser.Operator.OR;
if (stringQuery.isSetOperator() && stringQuery.getOperator() == Operator.AND) {
op = QueryParser.Operator.AND;
}
QueryParser queryParser = new LindenQueryParser(config);
String content = stringQuery.getQuery();
try {
queryParser.setDefaultOperator(op);
Query query = queryParser.parse(content);
// disable coord
if (query instanceof BooleanQuery) {
BooleanQuery bQuery = (BooleanQuery) query;
BooleanQuery booleanQuery = new BooleanQuery(stringQuery.isDisableCoord());
BooleanClause[] clauses = bQuery.getClauses();
for (BooleanClause clause : clauses) {
booleanQuery.add(clause);
}
booleanQuery.setBoost(query.getBoost());
query = booleanQuery;
}
return query;
} catch (ParseException e) {
throw new IOException(Throwables.getStackTraceAsString(e));
}
}
use of com.xiaomi.linden.thrift.common.LindenQuery in project linden by XiaoMi.
the class RangeQueryConstructor method construct.
@Override
protected Query construct(LindenQuery lindenQuery, LindenConfig config) throws IOException {
if (lindenQuery.isSetRangeQuery()) {
LindenRangeQuery lindenRangeQuery = lindenQuery.getRangeQuery();
LindenRange range = lindenRangeQuery.getRange();
String fieldName = range.getField();
LindenType type = range.getType();
String start = range.getStartValue();
String end = range.getEndValue();
boolean startClose = range.isStartClosed();
boolean endClose = range.isEndClosed();
Query query = null;
switch(type) {
case STRING:
case FACET:
query = new TermRangeQuery(fieldName, bytesRefVal(start), bytesRefVal(end), startClose, endClose);
break;
case INTEGER:
query = NumericRangeQuery.newIntRange(fieldName, intVal(start), intVal(end), startClose, endClose);
break;
case LONG:
query = NumericRangeQuery.newLongRange(fieldName, longVal(start), longVal(end), startClose, endClose);
break;
case DOUBLE:
query = NumericRangeQuery.newDoubleRange(fieldName, doubleVal(start), doubleVal(end), startClose, endClose);
break;
case FLOAT:
query = NumericRangeQuery.newFloatRange(fieldName, floatVal(start), floatVal(end), startClose, endClose);
break;
}
return query;
}
// todo throw exception.
return null;
}
Aggregations