addDocumentToQueue(getIndexName(botname, servername, channelname), doc);
}
public BooleanQuery getSearchQuery(Search.SearchBean bean)
{
BooleanQuery query = new BooleanQuery();
if (bean.getKeyword() != null &&
!bean.getKeyword().equals(""))
{
try
{
mKeywordQuery = QueryParser.parse(bean.getKeyword(), "message", getAnalyzer());
query.add(mKeywordQuery, true, false);
}
catch (org.apache.lucene.queryParser.ParseException e)
{
bean.addValidationError(new ValidationError.INVALID("keyword"));
}
}
if (bean.getDate() != null &&
!bean.getDate().equals(""))
{
try
{
Date parsed = Search.INPUT_DATE_FORMAT_SHORT.parse(bean.getDate());
Calendar cal = Calendar.getInstance();
cal.setTimeZone(TimeZone.getTimeZone(DroneConfig.getTimezone()));
cal.setTime(parsed);
Term begin = new Term("moment", DateField.dateToString(cal.getTime()));
cal.set(Calendar.HOUR, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 59);
Term end = new Term("moment", DateField.dateToString(cal.getTime()));
query.add(new RangeQuery(begin, end, true), true, false);
}
catch (Exception e)
{
bean.addValidationError(new ValidationError.WRONGFORMAT("date"));
}
}
boolean beginDatePresent = (bean.getBeginDate() != null && !bean.getBeginDate().equals(""));
boolean endDatePresent = (bean.getEndDate() != null && !bean.getEndDate().equals(""));
if (beginDatePresent && endDatePresent)
{
String beginDateFormatted = null;
String endDateFormatted = null;
try
{
Date beginDateParsed = Search.INPUT_DATE_FORMAT_SHORT.parse(bean.getBeginDate());
Date endDateParsed = Search.INPUT_DATE_FORMAT_SHORT.parse(bean.getEndDate());
Calendar cal = Calendar.getInstance();
cal.setTime(endDateParsed);
cal.set(Calendar.HOUR, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 59);
beginDateFormatted = DateField.dateToString(beginDateParsed);
endDateFormatted = DateField.dateToString(cal.getTime());
}
catch (ParseException e)
{
bean.addValidationError(new ValidationError.WRONGFORMAT("beginDate"));
bean.addValidationError(new ValidationError.WRONGFORMAT("endDate"));
}
if (bean.getValidationErrors().size() == 0)
{
Term begin = new Term("moment", beginDateFormatted);
Term end = new Term("moment", endDateFormatted);
query.add(new RangeQuery(begin, end, true), true, false);
}
}
else if (!beginDatePresent && !endDatePresent)
{
// noop; means they didn't try a date range
}
else
{
bean.addValidationError(new ValidationError.INCOMPLETE("dateRange"));
}
if (bean.getUser() != null &&
!bean.getUser().equals(""))
{
try
{
query.add(QueryParser.parse(bean.getUser(), "nickname", getAnalyzer()), true, false);
}
catch (org.apache.lucene.queryParser.ParseException e)
{
bean.addValidationError(new ValidationError.INVALID("user"));
}
}
if (bean.getChannel() != null &&
!bean.getChannel().equals("") &&
!bean.getChannel().equals("All"))
{
try
{
int pos = bean.getChannel().indexOf("#");
String botname = bean.getChannel().substring(0, pos - 3);
String channel = bean.getChannel().substring(pos + 1);
query.add(QueryParser.parse(channel, "channel", getAnalyzer()), true, false);
query.add(QueryParser.parse(botname, "botname", getAnalyzer()), true, false);
}
catch (org.apache.lucene.queryParser.ParseException e)
{
bean.addValidationError(new ValidationError.INVALID("channel"));
}