hits = searcher.search(query, new Sort(new SortField[] { dateSort, timeSort }));
// only highlight in the message
Query keywordQuery = search_tool.getKeywordQuery();
Highlighter highlighter = null;
if (keywordQuery != null)
{
Query rewritten_query = keywordQuery.rewrite(reader);
SimpleHTMLFormatter formatter = new SimpleHTMLFormatter("<span class=\"highlighted\">", "</span>");
highlighter = new Highlighter(formatter, new QueryScorer(rewritten_query));
}
for (int i = offset; i < LIMIT + offset; i++)
{
if (i >= hits.length())
{
// handle partial full pages
break;
}
Document doc = hits.doc(i);
// pull in our values
String nickname = doc.getField("nickname").stringValue();
String message = doc.getField("message").stringValue();
String channelname = doc.getField("channel").stringValue();
String botname = doc.getField("botname").stringValue();
String servername = doc.getField("servername").stringValue();
Date moment = DateField.stringToDate(doc.getField("moment").stringValue());
String day = mOutputDateFormat.format(moment);
String time = mOutputTimeFormat.format(moment);
String outputday = mDateFormat.format(moment);
// stolen directly from ChannelLog
String nickcolor = (String)mNickColors.get(nickname);
if (null == nickcolor)
{
nickcolor = ChannelLog.NICK_COLORS[mColorCounter++%ChannelLog.NICK_COLORS.length];
mNickColors.put(nickname, nickcolor);
}
mTemplate.setValue("bgcolor", nickcolor);
channelname = "#" + channelname;
// output a header if we're no longer in our little
// section of the world, i.e. date, server, channel, or
// bot changed
if (mCurrentDate == null || !mCurrentDate.equals(day) ||
mCurrentServername == null || !mCurrentServername.equals(servername) ||
mCurrentBotname == null || !mCurrentBotname.equals(botname) ||
mCurrentChannelname == null || !mCurrentChannelname.equals(channelname))
{
mTemplate.setValue("day", day);
mTemplate.setValue("botname", botname);
mTemplate.setValue("servername", servername);
mTemplate.setValue("channelname", channelname);
try
{
SearchBean bean = new SearchBean();
bean.setKeyword(submission.getKeyword());
bean.setChannel(botname + " - " + channelname);
bean.setDate(INPUT_DATE_FORMAT_SHORT.format(mDateFormat.parse(outputday)));
setNamedOutputBean("SearchBean", bean);
}
catch (ParseException e)
{
Logger
.getLogger("com.uwyn.drone.webui.elements.pub")
.severe(ExceptionUtils.getExceptionStackTrace(e));
}
setOutput("day", outputday);
setOutput("channelname", channelname);
setOutput("botname", botname);
setExitQuery(mTemplate, "show_channel_log", null, null);
mTemplate.setBlock("day_header", "day_header");
mCurrentDate = day;
mCurrentServername = servername;
mCurrentBotname = botname;
mCurrentChannelname = channelname;
}
else
{
mTemplate.setValue("day_header", "");
}
// output the message
mTemplate.setValue("time", time);
// translate the \u0001ACTION command which corresponds to
// /me so that the user's nickname is used instead
StringBuffer message_buf = new StringBuffer();
if (message.startsWith(ChannelLog.IRC_ACTION))
{
message_buf
.append(nickname)
.append(message.substring(ChannelLog.IRC_ACTION.length()));
}
else
{
message_buf.append(message);
}
String encoded_message = encodeHtml(message_buf.toString());
if (highlighter != null)
{
TokenStream tokenStream = new StandardAnalyzer().tokenStream("message", new StringReader(encoded_message));
String highlighted = highlighter.getBestFragments(tokenStream, encoded_message, 25, "...");
if (!highlighted.equals(""))
{
encoded_message = highlighted;
}