Ejemplo n.º 1
0
  protected int searchFlat(
      AbstractSearchRequest req,
      Collection<ArtifactInfo> result,
      IndexingContext context,
      Query query,
      int from,
      int aiCount)
      throws IOException {
    Hits hits =
        context
            .getIndexSearcher()
            .search(query, new Sort(new SortField(ArtifactInfo.UINFO, SortField.STRING)));

    if (hits == null || hits.length() == 0) {
      return 0;
    }

    if (req.isHitLimited() && hits.length() > req.getResultHitLimit()) {
      return AbstractSearchResponse.LIMIT_EXCEEDED;
    }

    int hitCount = hits.length();

    int start = 0; // from == FlatSearchRequest.UNDEFINED ? 0 : from;

    // we have to pack the results as long: a) we have found aiCount ones b) we depleted hits
    for (int i = start; i < hits.length(); i++) {
      Document doc = hits.doc(i);

      ArtifactInfo artifactInfo = IndexUtils.constructArtifactInfo(doc, context);

      if (artifactInfo != null) {
        artifactInfo.repository = context.getRepositoryId();

        artifactInfo.context = context.getId();

        result.add(artifactInfo);

        if (req.isHitLimited() && result.size() > req.getResultHitLimit()) {
          // we hit limit, back out now !!
          return AbstractSearchResponse.LIMIT_EXCEEDED;
        }
      }
    }

    return hitCount;
  }
Ejemplo n.º 2
0
  protected int searchGrouped(
      AbstractSearchRequest req,
      Map<String, ArtifactInfoGroup> result,
      Grouping grouping,
      IndexingContext context,
      Query query)
      throws IOException {
    Hits hits =
        context
            .getIndexSearcher()
            .search(query, new Sort(new SortField(ArtifactInfo.UINFO, SortField.STRING)));

    if (hits != null && hits.length() != 0) {
      int hitCount = hits.length();

      for (int i = 0; i < hits.length(); i++) {
        ArtifactInfo artifactInfo = IndexUtils.constructArtifactInfo(hits.doc(i), context);

        if (artifactInfo != null) {
          artifactInfo.repository = context.getRepositoryId();

          artifactInfo.context = context.getId();

          if (!grouping.addArtifactInfo(result, artifactInfo)) {
            // fix the hitCount accordingly
            hitCount--;
          }
        }
      }

      if (req.isHitLimited() && hits.length() > req.getResultHitLimit()) {
        return AbstractSearchResponse.LIMIT_EXCEEDED;
      }

      return hitCount;
    } else {
      return 0;
    }
  }