Search in sources :

Example 46 with LindenResult

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

the class TestLindenCore method testScoreModelPlugin.

@Test
public void testScoreModelPlugin() throws IOException {
    String bql = "select * from linden where title='lucene'" + " using score model plugin com.xiaomi.linden.core.plugin.TestScoreModelStrategy" + "(Long param1 = $long1, Map<String, Double> dict = {'中文': 1.0, 'b': 2.0});";
    LindenSearchRequest searchRequest = bqlCompiler.compile(bql).getSearchRequest();
    LindenResult result = lindenCore.search(searchRequest);
    Assert.assertEquals(4, result.getTotalHits());
    Assert.assertEquals(14.3, result.getHits().get(0).getScore(), 0.01);
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 47 with LindenResult

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

the class TestLindenCore method likeTest.

@Test
public void likeTest() throws Exception {
    String bql = "select * from linden by field1 like \"aa*\" source boost by 2";
    LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
    Query query = QueryConstructor.constructQuery(request.getQuery(), lindenConfig);
    Assert.assertTrue(query instanceof WildcardQuery);
    Assert.assertEquals("field1:aa*^2.0", query.toString());
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals(1, result.getTotalHits());
    bql = "select * from linden by field1 not like \"aaa*\" source";
    request = bqlCompiler.compile(bql).getSearchRequest();
    query = QueryConstructor.constructQuery(request.getQuery(), lindenConfig);
    Assert.assertTrue(query instanceof BooleanQuery);
    Assert.assertEquals("+*:* -field1:aaa*", query.toString());
    result = lindenCore.search(request);
    Assert.assertEquals(5, result.getTotalHits());
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) LindenResult(com.xiaomi.linden.thrift.common.LindenResult) Query(org.apache.lucene.search.Query) FlexibleQuery(com.xiaomi.linden.lucene.query.flexiblequery.FlexibleQuery) FilteredQuery(org.apache.lucene.search.FilteredQuery) LindenQuery(com.xiaomi.linden.thrift.common.LindenQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) DisjunctionMaxQuery(org.apache.lucene.search.DisjunctionMaxQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 48 with LindenResult

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

the class TestLindenCore method testSearchById.

@Test
public void testSearchById() throws IOException {
    String bql = "select * from linden where id in ('1', '2', '3')";
    LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals(3, result.getTotalHits());
    bql = "select * from linden where id = '1'";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(1, result.getTotalHits());
    bql = "select * from linden by id = '1'";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(1, result.getTotalHits());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 49 with LindenResult

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

the class TestLindenCore method testDisMax.

@Test
public void testDisMax() throws InterruptedException, IOException {
    String bql = "select * from linden source | select * from linden source";
    LindenSearchRequest lindenRequest = bqlCompiler.compile(bql).getSearchRequest();
    LindenResult result = lindenCore.search(lindenRequest);
    Assert.assertEquals(6, result.getTotalHits());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 50 with LindenResult

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

the class TestLindenCore method testFlexibleFilter.

@Test
public void testFlexibleFilter() throws Exception {
    String bql = "select name from linden  where flexible_query is 'qq音乐' full_match in (name^1.5) \n" + "USING MODEL test \n" + "begin\n" + " return score();\n" + "end\n" + "order by score,id  limit $offset, $length source";
    LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
    Filter filter = FilterConstructor.constructFilter(request.getFilter(), lindenConfig);
    Assert.assertEquals("QueryWrapperFilter(FlexibleQuery([name^1.5]:[qq,音,乐]fullMatch))", filter.toString());
    bql = "select name from linden \n" + "by flexible_query is \"lucene\" in (title^1.2) \n" + "USING MODEL test1 \n" + "begin \n" + "  return score() + 1;\n" + "end\n" + "where flexible_query is 'ddd' full_match in (field1)\n" + "USING MODEL filter_func begin return 1f; end \n" + "order by score,id limit $offset, $length source";
    request = bqlCompiler.compile(bql).getSearchRequest();
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals(1, result.getHitsSize());
    Assert.assertEquals(1f, result.getHits().get(0).getScore(), DELTA5);
    Assert.assertEquals("4", result.getHits().get(0).getId());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) Filter(org.apache.lucene.search.Filter) 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