{
Hits hits = null;
try
{
MultiReader reader = null;
ParallelMultiSearcher searcher = null;
List searchers = new ArrayList();
List readers = new ArrayList();
Collection bots = BotsRunner.getRepInstance().getBots();
Iterator iter = bots.iterator();
while (iter.hasNext())
{
Bot bot = (Bot)iter.next();
Iterator channels_it = bot.getJoinedChannels().iterator();
while (channels_it.hasNext())
{
Channel channel = ((Channel)channels_it.next());
StringBuffer key = new StringBuffer();
key
.append(Config.getRepInstance().getString("LUCENE_DIR"))
.append(File.separator)
.append(bot.getName())
.append("-")
.append(bot.getServer().getServerName())
.append("-")
.append(channel.getName().substring(1));
if (submission.getChannel() == null ||
submission.getChannel().equals(""))
{
IndexReader r = IndexReader.open(key.toString());
IndexSearcher s = new IndexSearcher(r);
searchers.add(s);
readers.add(r);
}
else
{
String submissionChannel = submission.getChannel().substring(submission.getChannel().indexOf("#"));
if (channel.getName().equals(submissionChannel))
{
IndexReader r = IndexReader.open(key.toString());
IndexSearcher s = new IndexSearcher(r);
searchers.add(s);
readers.add(r);
}
}
}
}
IndexSearcher[] searcherArray = (IndexSearcher[])searchers.toArray(new IndexSearcher[0]);
IndexReader[] readerArray = (IndexReader[])readers.toArray(new IndexReader[0]);
searcher = new ParallelMultiSearcher(searcherArray);
reader = new MultiReader(readerArray);
SortField dateSort = new SortField("momentDateSort", SortField.AUTO, true);
SortField timeSort = new SortField("momentTimeSort", SortField.AUTO, false);
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;
}
}
encoded_message = ChannelLog.convertUrl(encoded_message, ChannelLog.URL_HIGHLIGHT);
Matcher email_matcher = ChannelLog.EMAIL_HIGHLIGHT.matcher(encoded_message);
encoded_message = email_matcher.replaceAll("<a href=\"mailto:$1\">$1</a>");
mTemplate.setValue("nickname", nickname);
mTemplate.setValue("message", encoded_message);
mTemplate.appendBlock("messages", "message");
}
searcher.close();
reader.close();
}
catch (IOException e)
{
Logger
.getLogger("com.uwyn.drone.webui.elements.pub")