use of com.xiaomi.linden.thrift.common.SnippetParam in project linden by XiaoMi.
the class TestBQL method testSnippet.
@Test
public void testSnippet() {
String bql = "SELECT * FROM linden QUERY title LIKE 'sed*' snippet title, content";
LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
SnippetParam expected = new SnippetParam();
expected.addToFields(new SnippetField("title"));
expected.addToFields(new SnippetField("content"));
Assert.assertEquals(expected, lindenRequest.getSnippetParam());
}
use of com.xiaomi.linden.thrift.common.SnippetParam in project linden by XiaoMi.
the class BQLCompilerAnalyzer method exitSnippet_clause.
@Override
public void exitSnippet_clause(BQLParser.Snippet_clauseContext ctx) {
if (ctx.selection_list() != null) {
List<String> selections = (List<String>) valProperty.get(ctx.selection_list());
if (selections != null && !selections.isEmpty()) {
SnippetParam snippet = new SnippetParam();
for (String selection : selections) {
Map.Entry<String, LindenType> fieldNameAndType = getFieldNameAndType(selection);
LindenType type = fieldNameAndType.getValue();
String col = fieldNameAndType.getKey();
if (type == LindenType.STRING) {
snippet.addToFields(new SnippetField(col));
} else {
throw new ParseCancellationException("Snippet doesn't support this type " + type);
}
}
valProperty.put(ctx, snippet);
}
}
}
Aggregations