Search in sources :

Example 36 with LindenSearchRequest

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

the class CoreLindenServiceImpl method handleClusterSearchRequest.

@Override
public Future<LindenResult> handleClusterSearchRequest(final String bql) {
    final Stopwatch sw = Stopwatch.createStarted();
    return clusterExecutorPool.apply(new Function0<LindenResult>() {

        @Override
        public LindenResult apply() {
            LindenResult result = null;
            String logTag = null;
            try {
                long eps = sw.elapsed(TimeUnit.MILLISECONDS);
                if (eps > 10) {
                    LOGGER.warn("Warning: clusterExecutorPool took " + eps + "ms to start handleClusterSearchRequest.");
                    if (eps > clusterFuturePoolWaitTimeout) {
                        result = buildLindenFailedResult("Waiting time is too long, " + eps + "ms in cluster future pool");
                        return result;
                    }
                }
                LindenRequest request = bqlCompiler.compile(bql);
                if (request.isSetSearchRequest()) {
                    LindenSearchRequest searchRequest = request.getSearchRequest();
                    searchRequest.setOriginQuery(bql);
                    result = lindenCluster.search(searchRequest);
                    if (result.isSuccess()) {
                        logTag = "search";
                    } else {
                        logTag = "failureSearch";
                    }
                } else {
                    result = new LindenResult().setSuccess(false).setError("invalid search Bql");
                    logTag = "invalidSearchBql";
                }
            } catch (Exception e) {
                String errorStackInfo = Throwables.getStackTraceAsString(e);
                result = buildLindenFailedResult(errorStackInfo);
                logTag = "exceptionalSearchBql";
            } finally {
                metricsManager.time(sw.elapsed(TimeUnit.NANOSECONDS), logTag);
                result.setCost((int) sw.elapsed(TimeUnit.MILLISECONDS));
                if (result.isSuccess()) {
                    LOGGER.info("Cluster search request succeeded bql: {}, hits: {}, cost: {} ms.", bql, result.getHitsSize(), result.getCost());
                } else {
                    LOGGER.error("Cluster search request failed bql: {}, error: {}, cost: {} ms.", bql, result.getError(), result.getCost());
                }
                return result;
            }
        }
    });
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenRequest(com.xiaomi.linden.thrift.common.LindenRequest) Stopwatch(com.google.common.base.Stopwatch) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) IOException(java.io.IOException)

Example 37 with LindenSearchRequest

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

the class CoreLindenServiceImpl method handleClusterBqlRequest.

@Override
public Future<LindenResult> handleClusterBqlRequest(final String bql) {
    final Stopwatch sw = Stopwatch.createStarted();
    return clusterExecutorPool.apply(new Function0<LindenResult>() {

        @Override
        public LindenResult apply() {
            LindenResult result = null;
            String logTag = null;
            try {
                long eps = sw.elapsed(TimeUnit.MILLISECONDS);
                if (eps > 10) {
                    LOGGER.warn("Warning: clusterExecutorPool took " + eps + "ms to start handleClusterBqlRequest.");
                    if (eps > clusterFuturePoolWaitTimeout) {
                        result = buildLindenFailedResult("Waiting time is too long, " + eps + "ms in cluster future pool");
                        logTag = "poolWaitTimeout";
                        return result;
                    }
                }
                LindenRequest request = bqlCompiler.compile(bql);
                if (request.isSetSearchRequest()) {
                    LindenSearchRequest searchRequest = request.getSearchRequest();
                    searchRequest.setOriginQuery(bql);
                    result = lindenCluster.search(searchRequest);
                    if (result.isSuccess()) {
                        logTag = "search";
                    } else {
                        logTag = "failureSearch";
                    }
                } else if (request.isSetDeleteRequest()) {
                    Response response = lindenCluster.delete(request.getDeleteRequest());
                    result = new LindenResult().setSuccess(response.isSuccess()).setError(response.getError());
                    if (result.isSuccess()) {
                        logTag = "delete";
                    } else {
                        logTag = "failureDelete";
                    }
                } else {
                    result = buildLindenFailedResult("unsupported Bql");
                    logTag = "unsupportedBql";
                }
            } catch (Exception e) {
                String errorStackInfo = Throwables.getStackTraceAsString(e);
                result = buildLindenFailedResult(errorStackInfo);
                logTag = "exceptionalBql";
            } finally {
                metricsManager.time(sw.elapsed(TimeUnit.NANOSECONDS), logTag);
                result.setCost((int) sw.elapsed(TimeUnit.MILLISECONDS));
                if (result.isSuccess()) {
                    LOGGER.info("Cluster request succeeded bql: {}, hits: {}, cost: {} ms.", bql, result.getHitsSize(), result.getCost());
                } else {
                    LOGGER.error("Cluster request failed bql: {}, error: {}, cost: {} ms.", bql, result.getError(), result.getCost());
                }
                return result;
            }
        }
    });
}
Also used : Response(com.xiaomi.linden.thrift.common.Response) LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenRequest(com.xiaomi.linden.thrift.common.LindenRequest) Stopwatch(com.google.common.base.Stopwatch) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) IOException(java.io.IOException)

Example 38 with LindenSearchRequest

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

the class CoreLindenServiceImpl method handleBqlRequest.

// handle single instance request called warmer
@Override
public Future<LindenResult> handleBqlRequest(final String bql) {
    final Stopwatch sw = Stopwatch.createStarted();
    return instanceExecutorPool.apply(new Function0<LindenResult>() {

        @Override
        public LindenResult apply() {
            LindenResult result = null;
            String logTag = null;
            try {
                long eps = sw.elapsed(TimeUnit.MILLISECONDS);
                if (eps > 10) {
                    LOGGER.warn("Warning: instanceExecutorPool took " + eps + "ms to start handleBqlRequest.");
                    if (eps > instanceFuturePoolWaitTimeout) {
                        result = buildLindenFailedResult("Waiting time is too long, " + eps + "ms in instance future pool");
                        return result;
                    }
                }
                LindenRequest lindenRequest = bqlCompiler.compile(bql);
                if (lindenRequest.isSetSearchRequest()) {
                    LindenSearchRequest searchRequest = lindenRequest.getSearchRequest();
                    searchRequest.setOriginQuery(bql);
                    result = lindenCore.search(searchRequest);
                    if (result.isSuccess()) {
                        logTag = "singleInstanceSearch";
                    } else {
                        logTag = "failureSingleInstanceSearch";
                    }
                } else if (lindenRequest.isSetDeleteRequest()) {
                    Response response = lindenCore.delete(lindenRequest.getDeleteRequest());
                    result = new LindenResult().setSuccess(response.isSuccess()).setError(response.getError());
                    if (result.isSuccess()) {
                        logTag = "singleInstanceDelete";
                    } else {
                        logTag = "failureSingleInstanceDelete";
                    }
                } else {
                    result = buildLindenFailedResult("unsupported Bql");
                    logTag = "unsupportedSingleInstanceBql";
                }
            } catch (Exception e) {
                String errorStackInfo = Throwables.getStackTraceAsString(e);
                result = buildLindenFailedResult(errorStackInfo);
                logTag = "exceptionalSingleInstanceRequest";
            } finally {
                metricsManager.time(sw.elapsed(TimeUnit.NANOSECONDS), logTag);
                result.setCost((int) sw.elapsed(TimeUnit.MILLISECONDS));
                if (result.isSuccess()) {
                    LOGGER.info("Single instance request succeeded bql: {}, hits: {}, cost: {} ms.", bql, result.getHitsSize(), result.getCost());
                } else {
                    LOGGER.error("Single instance request failed bql: {}, error: {}, cost: {} ms.", bql, result.getError(), result.getCost());
                }
                return result;
            }
        }
    });
}
Also used : Response(com.xiaomi.linden.thrift.common.Response) LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenRequest(com.xiaomi.linden.thrift.common.LindenRequest) Stopwatch(com.google.common.base.Stopwatch) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) IOException(java.io.IOException)

Example 39 with LindenSearchRequest

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

the class TestLindenJiebaAnalyzerSearchMode method testSearchMode.

@Test
public void testSearchMode() throws IOException {
    String bql = "select * from linden by query is \"title:刘华清\"";
    LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals(2, result.getTotalHits());
    // phrase test
    bql = "select * from linden by query is 'title:\"刘华清\"'";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(2, result.getTotalHits());
    bql = "select * from linden by query is 'title:\"海军上将刘华清\"'";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(2, result.getTotalHits());
    // snippet test
    bql = "select * from linden by query is 'title:(海军上将刘华清中国龙)' snippet title";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(2, result.getTotalHits());
    Assert.assertEquals("<b>海军上将</b><b>刘华清</b>", result.getHits().get(0).getSnippets().get("title").getSnippet());
    Assert.assertEquals("<b>海军上将</b><b>刘华清</b>!!! <b>中国</b> 人民 李玉洁 尚铁龙 胡晓光", result.getHits().get(1).getSnippets().get("title").getSnippet());
    bql = "select * from linden by query is 'title:(海军中国铁龙)' snippet title";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(1, result.getTotalHits());
    Assert.assertEquals("<b>中国</b> 人民 李玉洁 尚铁龙 胡晓光", result.getHits().get(0).getSnippets().get("title").getSnippet());
}
Also used : LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 40 with LindenSearchRequest

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

the class TestLindenMMSeg4jAnalyzer method testQueryString.

@Test
public void testQueryString() throws IOException {
    String bql = "select * from linden by query is \"title:刘华清\"";
    LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
    LindenResult result = lindenCore.search(request);
    Assert.assertEquals(3, result.getTotalHits());
    // phrase test
    bql = "select * from linden by query is 'title:\"刘华清\"'";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(2, result.getTotalHits());
    bql = "select * from linden by query is 'title:\"海军上将刘华清\"'";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(2, result.getTotalHits());
    // snippet test
    bql = "select * from linden by query is 'title:(上将刘华清中国龙)' snippet title";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(3, result.getTotalHits());
    Assert.assertEquals("海军<b>上将</b><b>刘</b><b>华</b><b>清</b>!!! <b>中国</b> 人民 李玉洁 尚铁<b>龙</b> 胡晓光", result.getHits().get(0).getSnippets().get("title").getSnippet());
    bql = "select * from linden by query is 'title:(海军中国铁龙)' snippet title";
    request = bqlCompiler.compile(bql).getSearchRequest();
    result = lindenCore.search(request);
    Assert.assertEquals(2, result.getTotalHits());
    Assert.assertEquals("<b>海军</b>上将刘华清!!! <b>中国</b> 人民 李玉洁 尚<b>铁</b><b>龙</b> 胡晓光", result.getHits().get(0).getSnippets().get("title").getSnippet());
}
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