コード例 #1
0
 private CacheQuery createAppLogLinesQuery(RequestLogs requestLogs) {
   QueryBuilder queryBuilder =
       searchManager.buildQueryBuilderForClass(CapedwarfAppLogLine.class).get();
   Query query =
       queryBuilder
           .keyword()
           .onField(CapedwarfAppLogLine.REQUEST_ID)
           .matching(requestLogs.getRequestId())
           .createQuery();
   CacheQuery cacheQuery = searchManager.getQuery(query, CapedwarfAppLogLine.class);
   cacheQuery.sort(new Sort(new SortField(CapedwarfAppLogLine.SEQUENCE_NUMBER, SortField.LONG)));
   return cacheQuery;
 }
コード例 #2
0
  private CacheQuery createRequestLogsQuery(CapedwarfLogQuery logQuery) {
    LogQuery query = logQuery.getQuery();
    QueryBuilder queryBuilder =
        searchManager.buildQueryBuilderForClass(CapedwarfRequestLogs.class).get();
    List<Query> queries = new ArrayList<Query>();
    if (query.getStartTimeUsec() != null) {
      queries.add(
          queryBuilder
              .range()
              .onField(CapedwarfRequestLogs.END_TIME_USEC)
              .above(query.getStartTimeUsec())
              .createQuery());
    }
    if (query.getEndTimeUsec() != null) {
      queries.add(
          queryBuilder
              .range()
              .onField(CapedwarfRequestLogs.END_TIME_USEC)
              .below(query.getEndTimeUsec())
              .createQuery());
    }
    if (query.getMinLogLevel() != null) {
      queries.add(
          queryBuilder
              .range()
              .onField(CapedwarfRequestLogs.MAX_LOG_LEVEL)
              .above(query.getMinLogLevel().ordinal())
              .createQuery());
    }

    boolean onlyCompleteRequests = !Boolean.TRUE.equals(query.getIncludeIncomplete());
    if (onlyCompleteRequests) {
      queries.add(
          queryBuilder
              .keyword()
              .onField(CapedwarfRequestLogs.FINISHED)
              .matching(Boolean.TRUE)
              .createQuery());
    }

    Query luceneQuery = getQuery(queryBuilder, queries);
    CacheQuery cacheQuery = searchManager.getQuery(luceneQuery, CapedwarfRequestLogs.class);
    cacheQuery.sort(
        new Sort(new SortField(CapedwarfRequestLogs.END_TIME_USEC, SortField.LONG, true)));
    cacheQuery.firstResult(logQuery.getOptions().getOffset());
    if (logQuery.getOptions().getLimit() != null) {
      cacheQuery.maxResults(logQuery.getOptions().getLimit());
    }
    return cacheQuery;
  }
コード例 #3
0
  /** Execute Lucene index query. */
  private QueryResponse executeQuery(
      AdvancedCache<byte[], byte[]> cache, SerializationContext serCtx, QueryRequest request) {
    final SearchManager searchManager = Search.getSearchManager(cache);
    final SearchIntegrator searchFactory = searchManager.getSearchFactory();
    final QueryCache queryCache = ComponentRegistryUtils.getQueryCache(cache); // optional component

    LuceneQueryParsingResult parsingResult;
    Query luceneQuery;

    if (queryCache != null) {
      KeyValuePair<String, Class> queryCacheKey =
          new KeyValuePair<String, Class>(request.getJpqlString(), LuceneQueryParsingResult.class);
      parsingResult = queryCache.get(queryCacheKey);
      if (parsingResult == null) {
        parsingResult = parseQuery(cache, serCtx, request.getJpqlString(), searchFactory);
        queryCache.put(queryCacheKey, parsingResult);
      }
    } else {
      parsingResult = parseQuery(cache, serCtx, request.getJpqlString(), searchFactory);
    }

    luceneQuery = parsingResult.getQuery();

    if (!cache.getCacheConfiguration().compatibility().enabled()) {
      // restrict on entity type
      QueryBuilder qb =
          searchFactory.buildQueryBuilder().forEntity(parsingResult.getTargetEntity()).get();
      luceneQuery =
          qb.bool()
              .must(
                  qb.keyword()
                      .onField(TYPE_FIELD_NAME)
                      .ignoreFieldBridge()
                      .ignoreAnalyzer()
                      .matching(parsingResult.getTargetEntityName())
                      .createQuery())
              .must(luceneQuery)
              .createQuery();
    }

    CacheQuery cacheQuery = searchManager.getQuery(luceneQuery, parsingResult.getTargetEntity());

    if (parsingResult.getSort() != null) {
      cacheQuery = cacheQuery.sort(parsingResult.getSort());
    }

    int projSize = 0;
    if (parsingResult.getProjections() != null && !parsingResult.getProjections().isEmpty()) {
      projSize = parsingResult.getProjections().size();
      cacheQuery =
          cacheQuery.projection(parsingResult.getProjections().toArray(new String[projSize]));
    }
    if (request.getStartOffset() > 0) {
      cacheQuery = cacheQuery.firstResult((int) request.getStartOffset());
    }
    if (request.getMaxResults() > 0) {
      cacheQuery = cacheQuery.maxResults(request.getMaxResults());
    }

    List<?> list = cacheQuery.list();
    List<WrappedMessage> results =
        new ArrayList<WrappedMessage>(projSize == 0 ? list.size() : list.size() * projSize);
    for (Object o : list) {
      if (projSize == 0) {
        results.add(new WrappedMessage(o));
      } else {
        Object[] row = (Object[]) o;
        for (int j = 0; j < projSize; j++) {
          results.add(new WrappedMessage(row[j]));
        }
      }
    }

    QueryResponse response = new QueryResponse();
    response.setTotalResults(cacheQuery.getResultSize());
    response.setNumResults(list.size());
    response.setProjectionSize(projSize);
    response.setResults(results);

    return response;
  }