} else {
summary.add(new Fragment(parts[j]));
}
highlight = !highlight;
}
summary.add(new Ellipsis());
}
/* TODO MC BUG resolved 0000029 - if query terms do not occur on text, an empty summary is returned. Now it sends the first tokens. */
if (result==null || result.length==0) {
tokens = analyzer.tokenStream("content", new StringReader(text));
Token firstToken=null, lastToken=null;
Token token=null;
int maxLen=100; // the same as defined in SimpleFragmenter but it is private
/*
ArrayList<Token> titleTokens=new ArrayList<Token>();
ArrayList<Token> textTokens=new ArrayList<Token>();
boolean titleMatched=false;
boolean hasMatched=false; // exit match after match title the first time
// remove title from text. compares pairs of text
while ((titleMatched || !hasMatched) && (token=tokens.next())!=null) {
if (token.type().equals("<WORD>")) {
if (titleTokens.size()==0) {
titleTokens.add(token);
}
else if (textTokens.size()<titleTokens.size()) {
textTokens.add(token);
}
if (textTokens.size()==titleTokens.size()) {
// compare
titleMatched=true;
for (int i=0;i<textTokens.size() && titleMatched;i++) {
if (!textTokens.get(i).termText().equals(titleTokens.get(i).termText())) {
titleMatched=false;
}
}
if (titleMatched) { // try to match a larger pattern
titleTokens.add(textTokens.get(0));
textTokens.remove(0);
hasMatched=true;
}
else { // remove rest of title from text
if (hasMatched) {
firstToken=textTokens.get(titleTokens.size()-2);
}
else { // add one more token to title
titleTokens.add(textTokens.get(0));
textTokens.remove(0);
}
}
}
}
}
if (textTokens.size()==0) {
return summary;
}
for (int i=0;i<textTokens.size() && textTokens.get(i).endOffset()-firstToken.startOffset()<maxLen;i++) {
lastToken=textTokens.get(i);
}
*/
// read tokens until maxLen
while ((token=tokens.next())!=null) {
if (token.type().equals("<WORD>")) {
if (firstToken==null) {
firstToken=token;
}
else if (token.endOffset()-firstToken.startOffset()<maxLen) {
lastToken=token;
}
else {
break;
}
}
}
if (lastToken==null) {
lastToken=firstToken;
}
summary.add(new Fragment(text.substring(firstToken.startOffset(), lastToken.endOffset())));
summary.add(new Ellipsis());
}
/* TODO MC */
} catch (Exception e) {
// Nothing to do...