Search in sources :

Example 66 with LindenResult

use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.

the class TestLindenFacet method facetTest7.

// test with delete
@Test
public void facetTest7() throws Exception {
    LindenSearchRequest request = new LindenSearchRequest();
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals(13, result.getTotalHits());
    handleRequest(generateDeleteRequest("1"));
    lindenCore.commit();
    lindenCore.refresh();
    String bql = "select * from Linden browse by Author, PublishDate";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(12, result.getTotalHits());
    Assert.assertEquals(2, result.getFacetResultsSize());
    // Author facet
    Assert.assertEquals("LindenFacetResult(dim:Author, value:10, childCount:4, " + "labelValues:[LindenLabelAndValue(label:Lisa, value:4), " + "LindenLabelAndValue(label:Susan, value:4), " + "LindenLabelAndValue(label:Bob, value:1), " + "LindenLabelAndValue(label:Frank, value:1)])", result.getFacetResults().get(0).toString());
    // PublishDate facet
    Assert.assertEquals("LindenFacetResult(dim:PublishDate, value:10, childCount:4, " + "labelValues:[LindenLabelAndValue(label:2010, value:3), " + "LindenLabelAndValue(label:2012, value:3), " + "LindenLabelAndValue(label:1999, value:3), " + "LindenLabelAndValue(label:2013, value:1)])", result.getFacetResults().get(1).toString());
    handleRequest(generateIndexRequest("1", "cn", "Bob book 1", "Bob", "2010/10/15"));
    lindenCore.commit();
    lindenCore.refresh();
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 67 with LindenResult

use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.

the class TestLindenFacet method facetTest6.

// Early termination
@Test
public void facetTest6() throws Exception {
    LindenSearchRequest request = new LindenSearchRequest();
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals(13, result.getTotalHits());
    String bql = "select * from Linden browse by Author, PublishDate in top 5";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(5, result.getTotalHits());
    Assert.assertEquals(2, result.getFacetResultsSize());
    // Author facet
    Assert.assertEquals("LindenFacetResult(dim:Author, value:5, childCount:4, " + "labelValues:[LindenLabelAndValue(label:Lisa, value:2), LindenLabelAndValue(label:Bob, value:1), " + "LindenLabelAndValue(label:Susan, value:1), LindenLabelAndValue(label:Frank, value:1)])", result.getFacetResults().get(0).toString());
    // PublishDate facet
    Assert.assertEquals("LindenFacetResult(dim:PublishDate, value:5, childCount:3, " + "labelValues:[LindenLabelAndValue(label:2010, value:2), " + "LindenLabelAndValue(label:2012, value:2), " + "LindenLabelAndValue(label:1999, value:1)])", result.getFacetResults().get(1).toString());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 68 with LindenResult

use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.

the class TestLindenFacet method facetTest3.

// test with query and filter
@Test
public void facetTest3() throws Exception {
    LindenSearchRequest request = new LindenSearchRequest();
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals(13, result.getTotalHits());
    String bql = "select * from linden by query is 'Title:Lisa' where Language='en' browse by Author, PublishDate";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(2, result.getTotalHits());
    Assert.assertEquals(2, result.getFacetResultsSize());
    // Author facet
    Assert.assertEquals("LindenFacetResult(dim:Author, value:2, childCount:1, " + "labelValues:[LindenLabelAndValue(label:Lisa, value:2)])", result.getFacetResults().get(0).toString());
    // PublishDate facet
    Assert.assertEquals("LindenFacetResult(dim:PublishDate, value:2, childCount:1, " + "labelValues:[LindenLabelAndValue(label:2012, value:2)])", result.getFacetResults().get(1).toString());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 69 with LindenResult

use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.

the class TestLindenFieldCache method intListTest.

@Test
public void intListTest() throws IOException {
    String bql = "select * from linden by query is \"title:lucene\" " + "using score model test " + "begin " + "    float sum = 0;\n" + "    for (int a : ids_int()) {\n" + "      sum += a;\n" + "    }\n" + "    return sum;\n" + "end";
    LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals(10, result.getTotalHits());
    Assert.assertEquals(30, result.getHits().get(0).getScore(), 0.1f);
    bql = "select * from linden where ids_int = 2  " + "using score model test " + "begin " + "    float sum = 0;\n" + "    for (int a : ids_int()) {\n" + "      sum += a;\n" + "    }\n" + "    return sum;\n" + "end";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(3, result.getTotalHits());
    Assert.assertEquals(9, result.getHits().get(0).getScore(), 0.1f);
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 70 with LindenResult

use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.

the class TestLindenGroupSearch method groupSearchTest3.

// dynamic field
@Test
public void groupSearchTest3() throws IOException {
    String bql = "select * from linden order by rank group by cat1.STRING TOP 3 limit 0,10 source";
    LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
    Assert.assertEquals(true, request.isSetGroupParam());
    Assert.assertEquals("cat1", request.getGroupParam().getGroupField());
    Assert.assertEquals(3, request.getGroupParam().getGroupInnerLimit());
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals(true, result.isSuccess());
    Assert.assertEquals(5, result.getTotalHits());
    Assert.assertEquals(3, result.getTotalGroups());
    Assert.assertEquals(3, result.getHitsSize());
    Assert.assertEquals(2, result.getHits().get(0).getGroupHitsSize());
    Assert.assertEquals("10.3", result.getHits().get(0).getGroupHits().get(0).getFields().get("rank"));
    Assert.assertEquals("4.5", result.getHits().get(0).getGroupHits().get(1).getFields().get("rank"));
    Assert.assertEquals(1, result.getHits().get(1).getGroupHitsSize());
    Assert.assertEquals("10.0", result.getHits().get(1).getGroupHits().get(0).getFields().get("rank"));
    Assert.assertEquals(2, result.getHits().get(2).getGroupHitsSize());
    Assert.assertEquals("4.0", result.getHits().get(2).getGroupHits().get(0).getFields().get("rank"));
    Assert.assertEquals("1.2", result.getHits().get(2).getGroupHits().get(1).getFields().get("rank"));
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Aggregations

LindenResult (com.xiaomi.linden.thrift.common.LindenResult)79 LindenSearchRequest (com.xiaomi.linden.thrift.common.LindenSearchRequest)69 Test (org.junit.Test)69 IOException (java.io.IOException)7 LindenQuery (com.xiaomi.linden.thrift.common.LindenQuery)5 JSONObject (com.alibaba.fastjson.JSONObject)4 Stopwatch (com.google.common.base.Stopwatch)4 MultiLindenCoreImpl (com.xiaomi.linden.core.search.MultiLindenCoreImpl)3 LindenFlexibleQueryBuilder (com.xiaomi.linden.thrift.builder.query.LindenFlexibleQueryBuilder)3 LindenDeleteRequest (com.xiaomi.linden.thrift.common.LindenDeleteRequest)3 LindenHit (com.xiaomi.linden.thrift.common.LindenHit)3 LindenRequest (com.xiaomi.linden.thrift.common.LindenRequest)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 FlexibleQuery (com.xiaomi.linden.lucene.query.flexiblequery.FlexibleQuery)2 Response (com.xiaomi.linden.thrift.common.Response)2 BooleanQuery (org.apache.lucene.search.BooleanQuery)2 DisjunctionMaxQuery (org.apache.lucene.search.DisjunctionMaxQuery)2 FilteredQuery (org.apache.lucene.search.FilteredQuery)2 Query (org.apache.lucene.search.Query)2