logger.error("malformed pattern" + e.getMessage());
return Sequence.EMPTY_SEQUENCE;
}
}
//Walk through hits
final ExtArrayNodeSet r = new ExtArrayNodeSet();
final Tokenizer tok = context.getBroker().getTextEngine().getTokenizer();
Matcher matcher;
for (final NodeProxy current : result) {
Match nextMatch;
final Vector<NodeId> matchGid = new Vector<NodeId>();
//Get first match
nextMatch = current.getMatches();
//Remove previously found matches on current
current.setMatches(null);
//Iterate on attach matches, with unicity of related nodeproxy gid
while (nextMatch != null) {
final Hashtable<String, Match> matchTable = new Hashtable<String, Match>();
final NodeId nodeId = nextMatch.getNodeId();
//If current node id has not been previously processed
if (!matchGid.contains(nodeId)) {
final NodeProxy mcurrent = new NodeProxy(current.getDocument(), nodeId);
//Add it in node id array
matchGid.add(nodeId);
final String value = mcurrent.getNodeValue();
tok.setText(value);
int j = 0;
if (j < patterns.length) {
matcher = matchers[j];
} else
{break;}
String matchTerm = null;
TextToken token;
while ((token = tok.nextToken()) != null) {
String word = token.getText().toLowerCase();
matcher.reset(word);
matchers[0].reset(word);
if (matcher.matches()) {
j++;
if (matchTerm == null)
{matchTerm=word;}
else
{matchTerm = matchTerm + "\\W*" + word;}
if (j == patterns.length) {
//All terms found
if (matchTable.containsKey(matchTerm)) {
//Previously found matchTerm
final Match match = matchTable.get(matchTerm);
match.addOffset(token.startOffset(), matchTerm.length());
} else {
final Match match = nextMatch.createInstance(getExpressionId(),
nodeId, matchTerm);
match.addOffset(token.startOffset(), matchTerm.length());
matchTable.put(matchTerm,match);
}
//Start again on fist term
j = 0;
matcher = matchers[j];
matchTerm = null;
continue;
} else {
matcher = matchers[j];
}
} else if (j > 0 && matchers[0].matches()) {
//First search term found: start again
j = 1;
//Pattern term = patterns[j];
matcher = matchers[j];
matchTerm = word;
continue;
} else {
//Reset
j = 0;
matcher = matchers[j];
matchTerm = null;
continue;
}
}
//One or more match found
if (matchTable.size() != 0) {
final Enumeration<Match> eMatch = matchTable.elements();
while (eMatch.hasMoreElements()){
final Match match = eMatch.nextElement();
current.addMatch(match);
}
//Add current to result
r.add(current);
}
}
//Process next match
nextMatch = nextMatch.getNextMatch();
}