Exemplo n.º 1
0
  public void findIndexMatches(
      Index index,
      IndexQueryRequestor requestor,
      SearchParticipant participant,
      IJavaSearchScope scope,
      IProgressMonitor progressMonitor)
      throws IOException {
    if (progressMonitor != null && progressMonitor.isCanceled())
      throw new OperationCanceledException();

    resetQuery();
    SimpleSet intersectedNames = null;
    try {
      index.startQuery();
      do {
        SearchPattern pattern = currentPattern();
        EntryResult[] entries = pattern.queryIn(index);
        if (entries == null) return;

        SearchPattern decodedResult = pattern.getBlankPattern();
        SimpleSet newIntersectedNames = new SimpleSet(3);
        for (int i = 0, l = entries.length; i < l; i++) {
          if (progressMonitor != null && progressMonitor.isCanceled())
            throw new OperationCanceledException();

          EntryResult entry = entries[i];
          decodedResult.decodeIndexKey(entry.getWord());
          if (pattern.matchesDecodedKey(decodedResult)) {
            String[] names = entry.getDocumentNames(index);
            if (intersectedNames != null) {
              for (int j = 0, n = names.length; j < n; j++)
                if (intersectedNames.includes(names[j])) newIntersectedNames.add(names[j]);
            } else {
              for (int j = 0, n = names.length; j < n; j++) newIntersectedNames.add(names[j]);
            }
          }
        }

        if (newIntersectedNames.elementSize == 0) return;
        intersectedNames = newIntersectedNames;
      } while (hasNextQuery());
    } finally {
      index.stopQuery();
    }

    String containerPath = index.containerPath;
    char separator = index.separator;
    Object[] names = intersectedNames.values;
    for (int i = 0, l = names.length; i < l; i++)
      if (names[i] != null)
        acceptMatch(
            (String) names[i],
            containerPath,
            separator,
            null /*no pattern*/,
            requestor,
            participant,
            scope); // AndPatterns cannot provide the decoded result
  }