Esempio n. 1
0
 @Override
 public void visitMatchingTerms(IndexReader reader, String fieldName, MatchingTermVisitor mtv)
     throws IOException {
   boolean expanded = false;
   int prefixLength = prefix.length();
   TermEnum enumerator = reader.terms(new Term(fieldName, prefix));
   Matcher matcher = pattern.matcher("");
   try {
     do {
       Term term = enumerator.term();
       if (term != null) {
         String text = term.text();
         if ((!text.startsWith(prefix)) || (!term.field().equals(fieldName))) {
           break;
         } else {
           matcher.reset(text.substring(prefixLength));
           if (matcher.matches()) {
             mtv.visitMatchingTerm(term);
             expanded = true;
           }
         }
       }
     } while (enumerator.next());
   } finally {
     enumerator.close();
     matcher.reset();
   }
   if (!expanded) {
     System.out.println("No terms in " + fieldName + " field for: " + toString());
   }
 }
Esempio n. 2
0
  @Override
  public void visitMatchingTerms(IndexReader reader, String fieldName, MatchingTermVisitor mtv)
      throws IOException {
    int prefixLength = prefix.length();
    Terms terms = MultiFields.getTerms(reader, fieldName);
    if (terms != null) {
      Matcher matcher = pattern.matcher("");
      try {
        TermsEnum termsEnum = terms.iterator(null);

        TermsEnum.SeekStatus status = termsEnum.seekCeil(prefixRef);
        BytesRef text;
        if (status == TermsEnum.SeekStatus.FOUND) {
          text = prefixRef;
        } else if (status == TermsEnum.SeekStatus.NOT_FOUND) {
          text = termsEnum.term();
        } else {
          text = null;
        }

        while (text != null) {
          if (text != null && StringHelper.startsWith(text, prefixRef)) {
            String textString = text.utf8ToString();
            matcher.reset(textString.substring(prefixLength));
            if (matcher.matches()) {
              mtv.visitMatchingTerm(new Term(fieldName, textString));
            }
          } else {
            break;
          }
          text = termsEnum.next();
        }
      } finally {
        matcher.reset();
      }
    }
  }