current_distance = -1;  while ((token = tok.nextToken()) != null) { word = token.getText().toLowerCase(); if (current_distance > max_distance) {  j = 0; term = patterns[j]; matcher = matchers[j]; current_distance = -1; continue;
String value; Pattern term; String word; TextToken token; NodeProxy current; ExtArrayNodeSet r = new ExtArrayNodeSet(100); Matcher matcher; Tokenizer tok = context.getBroker().getTextEngine().getTokenizer(); int j; int current_distance; for (Iterator i = result.iterator(); i.hasNext();) { current = (NodeProxy) i.next(); value = current.getNodeValueSeparated(); tok.setText(value); j = 0; if (j < patterns.length) { term = patterns[j]; matcher = matchers[j]; } else { break; }  current_distance = -1;  while ((token = tok.nextToken()) != null) { word = token.getText().toLowerCase(); if (current_distance > max_distance) {  j = 0; term = patterns[j]; matcher = matchers[j]; current_distance = -1; } matcher.reset(word); matchers[0].reset(word); if (matcher.matches()) { boolean withIn = current_distance >= min_distance ? true : false; current_distance = 0; j++; if (j == patterns.length) {  if (withIn) { r.add(current); } break; } else { term = patterns[j]; matcher = matchers[j]; } } else if (j > 0 && matchers[0].matches()) {  j = 1; term = patterns[j]; matcher = matchers[j]; current_distance = 0; continue; } if (-1 < current_distance) { ++current_distance; }  }
    private Sequence patternMatch(XQueryContext context, NodeSet result) {	// generate list of search term patterns	Pattern patterns[] = new Pattern[terms.length];        Matcher matchers[] = new Matcher[terms.length];	for (int i = 0; i < patterns.length; i++)	    try {                patterns[i] = Pattern.compile(GlobToRegex.globToRegexp(terms[i]), 					      Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);                matchers[i] = patterns[i].matcher("");	    } catch (PatternSyntaxException e) {		LOG.warn("malformed pattern", e);		return Sequence.EMPTY_SEQUENCE;	    }		// walk through hits and calculate term-distances	String value;	Pattern term;	String word;	TextToken token;	NodeProxy current;	ExtArrayNodeSet r = new ExtArrayNodeSet(100);	Matcher matcher;	Tokenizer tok = context.getBroker().getTextEngine().getTokenizer();	int j;	int current_distance;	for (Iterator i = result.iterator(); i.hasNext();) {	    current = (NodeProxy) i.next();	    value = current.getNodeValueSeparated();	    tok.setText(value);	    j = 0;	    if (j < patterns.length) {		term = patterns[j];                matcher = matchers[j];            } else {		break;	    }	    current_distance = -1;	    	    while ((token = tok.nextToken()) != null) {		word = token.getText().toLowerCase();		if (current_distance > max_distance) {		    // reset		    j = 0;		    term = patterns[j];		    matcher = matchers[j];		    current_distance = -1;		    continue;		}		matcher.reset(word);		matchers[0].reset(word);		if (matcher.matches()) {		    boolean withIn = current_distance >= min_distance ? true : false;		    current_distance = 0;		    j++;		    if (j == patterns.length) {			// all terms found			if (withIn) {			    r.add(current);			}			break;		    } else {			term = patterns[j];                        matcher = matchers[j];		    }		} else if (j > 0 && matchers[0].matches()) {		    // first search term found: start again		    j = 1;		    term = patterns[j];		    matcher = matchers[j];		    current_distance = 0;		    continue;		} else if (-1 < current_distance) {		    ++current_distance;		}			    }	}	return r;    }