Search in sources :

Example 81 with LindenSearchRequest

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

the class TestLindenFacet method facetTest1.

// No query, no filter
@Test
public void facetTest1() 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, PublishDate(2), PublishDate(10, '2010'), " + "PublishDate(10, '2010/10'), PublishDate(10, '2010/10/15')," + "PublishDate(10, '2010/13'), Author(10, 'non-existent-path')";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(13, result.getTotalHits());
    Assert.assertEquals(8, result.getFacetResultsSize());
    // Author facet
    Assert.assertEquals("LindenFacetResult(dim:Author, value:11, childCount:4, " + "labelValues:[LindenLabelAndValue(label:Lisa, value:4), " + "LindenLabelAndValue(label:Susan, value:4), " + "LindenLabelAndValue(label:Bob, value:2), " + "LindenLabelAndValue(label:Frank, value:1)])", result.getFacetResults().get(0).toString());
    // PublishDate facet
    Assert.assertEquals("LindenFacetResult(dim:PublishDate, value:11, childCount:4, " + "labelValues:[LindenLabelAndValue(label:2010, value:4), " + "LindenLabelAndValue(label:2012, value:3), " + "LindenLabelAndValue(label:1999, value:3), " + "LindenLabelAndValue(label:2013, value:1)])", result.getFacetResults().get(1).toString());
    // Top 2 PublishDate facet
    Assert.assertEquals("LindenFacetResult(dim:PublishDate, value:11, childCount:4, " + "labelValues:[LindenLabelAndValue(label:2010, value:4), " + "LindenLabelAndValue(label:2012, value:3)])", result.getFacetResults().get(2).toString());
    // PublishDate facet under path 2010
    Assert.assertEquals("LindenFacetResult(dim:PublishDate, path:2010, value:4, childCount:2, " + "labelValues:[LindenLabelAndValue(label:10, value:3), " + "LindenLabelAndValue(label:11, value:1)])", result.getFacetResults().get(3).toString());
    // PublishDate facet under path 2010,10
    Assert.assertEquals("LindenFacetResult(dim:PublishDate, path:2010/10, value:3, childCount:3, " + "labelValues:[LindenLabelAndValue(label:15, value:1), " + "LindenLabelAndValue(label:20, value:1), " + "LindenLabelAndValue(label:25, value:1)])", result.getFacetResults().get(4).toString());
    // PublishDate facet under path 2010,10,15
    Assert.assertEquals("LindenFacetResult(dim:PublishDate, path:2010/10/15, value:0, childCount:0)", result.getFacetResults().get(5).toString());
    // Non-existent-path
    Assert.assertEquals("LindenFacetResult(dim:PublishDate, path:2010/13, value:0, childCount:0)", result.getFacetResults().get(6).toString());
    // Non-existent-path
    Assert.assertEquals("LindenFacetResult(dim:Author, path:non-existent-path, value:0, childCount:0)", result.getFacetResults().get(7).toString());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 82 with LindenSearchRequest

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

the class TestLindenFacet method facetTest5.

// Drill sideways
@Test
public void facetTest5() 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 drill sideways PublishDate('2010')";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(4, result.getTotalHits());
    Assert.assertEquals(2, result.getFacetResultsSize());
    // Author facet under PublishDate 2010
    Assert.assertEquals("LindenFacetResult(dim:Author, value:4, childCount:2, " + "labelValues:[LindenLabelAndValue(label:Bob, value:2), LindenLabelAndValue(label:Lisa, value:2)])", result.getFacetResults().get(0).toString());
    // PublishDate facet is not effected by drill down Path
    Assert.assertEquals("LindenFacetResult(dim:PublishDate, value:11, childCount:4, " + "labelValues:[LindenLabelAndValue(label:2010, value:4), LindenLabelAndValue(label:2012, value:3), " + "LindenLabelAndValue(label:1999, value:3), LindenLabelAndValue(label:2013, 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 83 with LindenSearchRequest

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

the class TestLindenFacet method facetTest8.

// test facet source
@Test
public void facetTest8() throws Exception {
    String bql = "select * from Linden browse by Author, PublishDate source";
    LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals(13, result.getTotalHits());
    Assert.assertEquals(2, result.getFacetResultsSize());
    Assert.assertEquals("LindenHit(id:1, score:1.0, source:{\"PublishDate\":\"2010/10/15\",\"Language\":\"cn\",\"Author\":\"Bob\",\"id\":\"1\"})", result.getHits().get(0).toString());
    bql = "select Author from Linden browse by Author, PublishDate source";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(result.getHits().get(0).toString(), "LindenHit(id:1, score:1.0, source:{\"Author\":\"Bob\",\"id\":\"1\"})");
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 84 with LindenSearchRequest

use of com.xiaomi.linden.thrift.common.LindenSearchRequest 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 85 with LindenSearchRequest

use of com.xiaomi.linden.thrift.common.LindenSearchRequest 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)

Aggregations

LindenSearchRequest (com.xiaomi.linden.thrift.common.LindenSearchRequest)95 Test (org.junit.Test)90 LindenResult (com.xiaomi.linden.thrift.common.LindenResult)69 LindenQuery (com.xiaomi.linden.thrift.common.LindenQuery)13 LindenFilter (com.xiaomi.linden.thrift.common.LindenFilter)9 LindenBooleanQueryBuilder (com.xiaomi.linden.thrift.builder.query.LindenBooleanQueryBuilder)5 LindenBooleanFilter (com.xiaomi.linden.thrift.common.LindenBooleanFilter)5 IOException (java.io.IOException)5 JSONObject (com.alibaba.fastjson.JSONObject)4 LindenBooleanSubFilter (com.xiaomi.linden.thrift.common.LindenBooleanSubFilter)4 LindenDeleteRequest (com.xiaomi.linden.thrift.common.LindenDeleteRequest)4 LindenScoreModel (com.xiaomi.linden.thrift.common.LindenScoreModel)4 Stopwatch (com.google.common.base.Stopwatch)3 MultiLindenCoreImpl (com.xiaomi.linden.core.search.MultiLindenCoreImpl)3 LindenFlexibleQueryBuilder (com.xiaomi.linden.thrift.builder.query.LindenFlexibleQueryBuilder)3 LindenFacet (com.xiaomi.linden.thrift.common.LindenFacet)3 LindenFacetDimAndPath (com.xiaomi.linden.thrift.common.LindenFacetDimAndPath)3 LindenFacetParam (com.xiaomi.linden.thrift.common.LindenFacetParam)3 LindenRequest (com.xiaomi.linden.thrift.common.LindenRequest)3 LindenTerm (com.xiaomi.linden.thrift.common.LindenTerm)3