Search in sources :

Example 36 with LindenResult

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

the class TestLindenServer method assertHits.

private static LindenResult assertHits(String bql, int hits, int totalHits, String msg) throws Exception {
    LindenResult result = clusterClient.search(bql);
    if (result.isSuccess()) {
        try {
            if (hits >= 0) {
                Assert.assertEquals(hits, result.getHitsSize());
                Assert.assertEquals(totalHits, result.getTotalHits());
            }
            if (msg != null) {
                if (msg.startsWith("{")) {
                    Assert.assertEquals(msg, result.getHits().get(0).getSource());
                } else {
                    String[] ids = msg.split(",");
                    for (int i = 0; i < ids.length; i++) {
                        Assert.assertEquals(ids[i], result.getHits().get(i).getId());
                    }
                }
            }
        } catch (Throwable t) {
            System.out.println(result);
            throw t;
        }
    } else {
        throw new Exception(result.getError());
    }
    return result;
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) IOException(java.io.IOException)

Example 37 with LindenResult

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

the class TestLindenServer method flexibleQueryTest.

@Test
public void flexibleQueryTest() throws Exception {
    // full match
    String bql = "select * from linden by flexible_query is 'bank of china' " + "full_match in (sName^0.9,address^0.1) \n" + "using model func\n" + "begin\n" + "    int fieldsLength = getFieldLength();\n" + "    float sum = 0f, nameAdjacentBase = 1.2f;\n" + "    for (int i = 0; i < fieldsLength; ++i) {\n" + "        int matched = 0, numAdjacent = 0;\n" + "        float subSum = 0;\n" + "        for (int j = 0; j < getTermLength(); ++j) {\n" + "            if (isMatched(i, j)) {\n" + "                subSum += getScore(i, j);\n" + "                ++matched;\n" + "            }\n" + "            if (j > 0 && isMatched(i, j - 1)) {\n" + "                if (position(i, j) - position(i, j - 1)==1) {\n" + "                    numAdjacent += 1;\n" + "                }\n" + "            }\n" + "        }\n" + "        subSum *= (float) matched / getTermLength();\n" + "        if (getTermLength() > 1) {\n" + "            subSum *= (1.0f + nameAdjacentBase * numAdjacent / (getTermLength() - 1));\n" + "        }\n" + "        sum += subSum;\n" + "    }\n" + "    return sum; \n" + "end\n" + "where distance(119.4758, 26.0034) in 50 or catId = 8\n" + "explain\n" + "source";
    assertHits(bql, 2, 2, "201", 1.801f, null);
    bql = "select * from linden by flexible_query is 'Cloud^5 Hotel^2' \n" + "full_match in (sName^0.9,address^0.1) \n" + "using model func\n" + "begin\n" + "    float sum = 0f;\n" + "    for (int i = 0; i < getFieldLength(); ++i) {\n" + "        for (int j = 0; j < getTermLength(); ++j) {\n" + "            sum += getScore(i, j);\n" + "        }\n" + "    }\n" + "    return sum;" + "end\n" + "source explain";
    LindenResult result = assertHits(bql, 1, 1, null);
    Assert.assertEquals("0.91 * 0.10 * 5.00 -- (cloud 3)", result.getHits().get(0).getExplanation().getDetails().get(1).getDetails().get(0).getDescription());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) Test(org.junit.Test)

Example 38 with LindenResult

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

the class TestLindenServerWithFacet method aggregationTest.

@Test
public void aggregationTest() throws Exception {
    String bql = "select * from linden aggregate by Price({*, 10}, [10, 20}, [20, 30}, [50, 100}, [100, *})";
    LindenResult result = clusterClient.search(bql);
    Assert.assertEquals("[AggregationResult(field:Price, labelValues:[LindenLabelAndValue(label:{*,10}, value:2), " + "LindenLabelAndValue(label:[10,20}, value:4), LindenLabelAndValue(label:[20,30}, value:5), " + "LindenLabelAndValue(label:[50,100}, value:1), LindenLabelAndValue(label:[100,*}, value:2)])]", result.getAggregationResults().toString());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) Test(org.junit.Test)

Example 39 with LindenResult

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

the class TestLindenServerWithFacet method basicTest.

@Test
public void basicTest() throws Exception {
    String bql = "select * from linden browse by PublishDate, Author, Author(2), PublishDate(10, '2010'), " + "PublishDate(10, '2010/10'), PublishDate(10, '2010/10/15'), PublishDate(10, '2010/13')";
    LindenResult result = clusterClient.search(bql);
    Assert.assertEquals(17, result.getTotalHits());
    Assert.assertEquals(7, result.getFacetResultsSize());
    Assert.assertEquals("LindenFacetResult(dim:PublishDate, value:15, childCount:5, " + "labelValues:[LindenLabelAndValue(label:2010, value:6), " + "LindenLabelAndValue(label:2012, value:4), " + "LindenLabelAndValue(label:1999, value:3), " + "LindenLabelAndValue(label:2011, value:1), " + "LindenLabelAndValue(label:2013, value:1)])", result.getFacetResults().get(0).toString());
    Assert.assertEquals("LindenFacetResult(dim:Author, value:15, childCount:5, " + "labelValues:[LindenLabelAndValue(label:Susan, value:5), " + "LindenLabelAndValue(label:Bob, value:4), " + "LindenLabelAndValue(label:Lisa, value:4), " + "LindenLabelAndValue(label:Frank, value:1), " + "LindenLabelAndValue(label:Sue, value:1)])", result.getFacetResults().get(1).toString());
    Assert.assertEquals("LindenFacetResult(dim:Author, value:15, childCount:4, " + "labelValues:[LindenLabelAndValue(label:Lisa, value:4), LindenLabelAndValue(label:Susan, value:4)])", result.getFacetResults().get(2).toString());
    Assert.assertEquals("LindenFacetResult(dim:PublishDate, path:2010, value:6, childCount:3, " + "labelValues:[LindenLabelAndValue(label:10, value:3), " + "LindenLabelAndValue(label:11, value:2), " + "LindenLabelAndValue(label:12, value:1)])", result.getFacetResults().get(3).toString());
    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());
    Assert.assertEquals("LindenFacetResult(dim:PublishDate, path:2010/10/15, value:0, childCount:0)", result.getFacetResults().get(5).toString());
    Assert.assertEquals("LindenFacetResult(dim:PublishDate, path:2010/13, value:0, childCount:0)", result.getFacetResults().get(6).toString());
    bql = "select * from Linden query Language='en' browse by Author";
    result = clusterClient.search(bql);
    Assert.assertEquals(10, result.getTotalHits());
    Assert.assertEquals(1, result.getFacetResultsSize());
    Assert.assertEquals("LindenFacetResult(dim:Author, value:9, childCount:5, " + "labelValues:[LindenLabelAndValue(label:Susan, value:4), " + "LindenLabelAndValue(label:Lisa, value:2), " + "LindenLabelAndValue(label:Bob, value:1), " + "LindenLabelAndValue(label:Frank, value:1), " + "LindenLabelAndValue(label:Sue, value:1)])", result.getFacetResults().get(0).toString());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) Test(org.junit.Test)

Example 40 with LindenResult

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

the class TestLindenMetricPlugin method basicTest.

@Test
public void basicTest() throws Exception {
    LindenSearchRequest request = new LindenSearchRequest().setQuery(LindenQueryBuilder.buildTermQuery("title", "lucene"));
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals(4, result.getTotalHits());
}
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