* @param context
* @param result
*/
private Sequence exactMatch(XQueryContext context, String[] terms, NodeSet result) {
TextToken token;
final NodeSet r = new ExtArrayNodeSet();
final Tokenizer tok = context.getBroker().getTextEngine().getTokenizer();
//Define search phrase for matches
String matchTerm = "";
for (int k = 0; k < terms.length ; k++) {
matchTerm = matchTerm + terms[k];
if (k != terms.length - 1)
{matchTerm = matchTerm + "\\W*";}
}
//Iterate on results
for (final NodeProxy current : result) {
final Vector<NodeId> matchNodeIDs = new Vector<NodeId>();
//Get first match
Match nextMatch = current.getMatches();
//Remove previously found matches on current
current.setMatches(null);
//Iterate on attach matches, with unicity of related nodeproxy gid
String term;
while(nextMatch != null) {
final NodeId nodeId= nextMatch.getNodeId();
//If current node id has not been previously processed
if (!matchNodeIDs.contains(nodeId)) {
final NodeProxy mcurrent = new NodeProxy(current.getDocument(), nodeId);
Match match = null;
int firstOffset = -1;
matchNodeIDs.add(nodeId);
final String value = mcurrent.getNodeValue();
tok.setText(value);
int j = 0;
if (j < terms.length)
{term = terms[j];}
else
{break;}
int frequency = 0;
while ((token = tok.nextToken()) != null) {
final String word = token.getText().toLowerCase();
if (word.equalsIgnoreCase(term)) {
j++;
if (j == terms.length) {
//All terms found
if (match == null)
{match = nextMatch.createInstance(getExpressionId(),
nodeId, matchTerm);}
if (firstOffset < 0)
{firstOffset = token.startOffset();}
match.addOffset(firstOffset, token.endOffset() - firstOffset);
frequency++;
//Start again on fist term
j = 0;
term = terms[j];
continue;
} else {
term = terms[j];
if (firstOffset < 0)
{firstOffset = token.startOffset();}
}
} else if (j > 0 && word.equalsIgnoreCase(terms[0])) {
//First search term found: start again
j = 1;
term = terms[j];
firstOffset = token.startOffset();
continue;
} else {
//Reset
j = 0;
firstOffset = -1;
term = terms[j];
}
}
//If phrase found
if (frequency != 0) {
//Add new match to current
current.addMatch(match);
//Add current to result
r.add(current);
//Reset frequency
frequency=0;
}
}
//Process next match