Search in sources :

Example 61 with LindenResult

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

the class TestLindenFacet method facetTest9.

// test facet field index as normal field
@Test
public void facetTest9() throws Exception {
    String bql = "select * from Linden where Author in ('Bob', 'Frank') source";
    LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals(3, result.getHitsSize());
    bql = "select * from Linden where Author not in ('Bob', 'Frank') source";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(10, result.getHitsSize());
    bql = "select * from Linden query Author = 'Susan' source";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(4, result.getHitsSize());
    bql = "select * from Linden where Author > 'A' and Author < 'G' source";
    // Bob and Frank
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(3, result.getHitsSize());
    bql = "select * from Linden where Author is null source";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(2, result.getHitsSize());
    bql = "select * from Linden where Author is not null source";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(10, result.getHitsSize());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 62 with LindenResult

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

the class TestLindenFacet method facetTest10.

// dynamic field
@Test
public void facetTest10() throws Exception {
    String bql = "select * from Linden browse by Author.FACET, PublishDate.facet 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\"})");
    bql = "select * from Linden browse by Author.FACET, PublishDate.FACET drill down PublishDate.FACET('2010')";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(4, result.getTotalHits());
    Assert.assertEquals(2, result.getFacetResultsSize());
    // PublishDate facet
    Assert.assertEquals("LindenFacetResult(dim:PublishDate, value:4, childCount:1, labelValues:[LindenLabelAndValue(label:2010, value:4)])", result.getFacetResults().get(1).toString());
    bql = "select * from Linden browse by Author.FACET, PublishDate.FACET drill sideways PublishDate.FACET('2010')";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(4, result.getTotalHits());
    Assert.assertEquals(2, result.getFacetResultsSize());
    // 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 63 with LindenResult

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

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

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

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