Search in sources :

Example 1 with SnippetField

use of com.xiaomi.linden.thrift.common.SnippetField 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());
}
Also used : SnippetField(com.xiaomi.linden.thrift.common.SnippetField) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) SnippetParam(com.xiaomi.linden.thrift.common.SnippetParam) Test(org.junit.Test)

Example 2 with SnippetField

use of com.xiaomi.linden.thrift.common.SnippetField 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);
        }
    }
}
Also used : ParseCancellationException(org.antlr.v4.runtime.misc.ParseCancellationException) LindenType(com.xiaomi.linden.thrift.common.LindenType) SnippetField(com.xiaomi.linden.thrift.common.SnippetField) List(java.util.List) ArrayList(java.util.ArrayList) SnippetParam(com.xiaomi.linden.thrift.common.SnippetParam) Map(java.util.Map) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap)

Aggregations

SnippetField (com.xiaomi.linden.thrift.common.SnippetField)2 SnippetParam (com.xiaomi.linden.thrift.common.SnippetParam)2 LindenSearchRequest (com.xiaomi.linden.thrift.common.LindenSearchRequest)1 LindenType (com.xiaomi.linden.thrift.common.LindenType)1 AbstractMap (java.util.AbstractMap)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ParseCancellationException (org.antlr.v4.runtime.misc.ParseCancellationException)1 Test (org.junit.Test)1