예제 #1
0
  private IndexQueryResult processSearchRequest(Inquiry request, IndexQuery query) {
    IndexQueryResult result = new IndexQueryResult().withQueryname(query.getQueryname());

    try {
      int maxRows = _maxRows;
      if (request.getMaxrows() != null) {
        int requestRows = request.getMaxrows();
        if (requestRows != 0 && requestRows < maxRows) {
          maxRows = requestRows;
        }
      }

      boolean hasMore =
          invokeInSession(
              request.getSecurityToken(),
              new IndexQueryInvoker(
                  request,
                  query,
                  result,
                  getAttributeMapping(),
                  getFallbackDataProvider(),
                  maxRows));

      if (hasMore) {
        Logger.debug("Result contains more than " + maxRows + " rows, adding limit reached flag");
        result.setLimitreached(new LimitReached());
      }
    } catch (DfException ex) {
      Logger.error(ex.getMessage(), ex);
      handleException(ex, result);
    }
    return result;
  }
예제 #2
0
  private void addFallBackResult(Inquiry request, IndexQuery query, IndexQueryResult result) {
    try {
      Set<String> attributes = new HashSet<>();
      for (ResultField resultField : request.getResultfields()) {
        attributes.add(resultField.getName());
      }
      Map<String, String> noData = getFallbackDataProvider().getNoResultData(attributes);
      if (noData == null || noData.isEmpty()) {
        return;
      }

      Item item = new Item();
      for (ResultField resultField : request.getResultfields()) {
        String attrName = resultField.getName();
        String value = noData.get(resultField.getName());
        RField rField = new RField().withName(attrName).withValue(value);
        item.withRfields(rField);
      }
      item.setObjectname(getAttributeMapping().getDefaultType());
      item.setMediastatus("m");

      if (request.getImages() == YNBool.Y) {
        ImageProcessor imageProcessor =
            new ImageProcessor(request, query, getFallbackDataProvider());
        imageProcessor.processNoResultImage(item);
      }

      result.withItems(item);
    } catch (DfException ex) {
      Logger.error(ex.getMessage(), ex);
      handleException(ex, result);
    }
  }
예제 #3
0
  @Override
  protected Inquiryresult doProcess(Inquiry request, String userName) {
    Inquiryresult result = new Inquiryresult();
    result.setSessionname(request.getSessionname());
    for (IndexQuery query : request.getIndexqueries()) {
      result.getIndexqueryresults().add(processSearchRequest(request, query));
    }

    boolean hasData = false;
    boolean countQuery = request.getCount() == YNBool.Y;
    for (IndexQueryResult indexQueryResult : result.getIndexqueryresults()) {
      if (countQuery) {
        Integer retCount = indexQueryResult.getRetCount();
        hasData = retCount != null && retCount > 0;
      } else {
        List<Item> items = indexQueryResult.getItems();
        hasData = items != null && !items.isEmpty();
      }
      if (hasData) {
        break;
      }
    }

    if (!hasData && _performFallback) {
      Logger.debug("Query result contains no data, adding fake data");
      IndexQuery query = request.getIndexqueries().get(0);
      IndexQueryResult indexQueryResult = result.getIndexqueryresults().get(0);
      if (countQuery) {
        indexQueryResult.setRetCount(1);
      } else {
        addFallBackResult(request, query, indexQueryResult);
      }
    }

    return result;
  }
예제 #4
0
 private void handleException(DfException exception, IndexQueryResult result) {
   result.setResponseCode(GenericCode.SYNTAX_ERROR);
 }