// Verify credentials.
if (credentials != null && (!credentials.containsKey(query.group) ||
!credentials.get(query.group).equals(query.token))) {
LOG.info(String.format("Access denied for (%s, %s)", query.group, query.token));
throw new TrecSearchException("Invalid credentials: access denied.");
}
List<TResult> results = Lists.newArrayList();
long startTime = System.currentTimeMillis();
try {
Filter filter =
NumericRangeFilter.newLongRange(StatusField.ID.name, 0L, query.max_id, true, true);
Query q = QUERY_PARSER.parse(query.text);
int num = query.num_results > 10000 ? 10000 : query.num_results;
TopDocs rs = searcher.search(q, filter, num);
for (ScoreDoc scoreDoc : rs.scoreDocs) {
Document hit = searcher.doc(scoreDoc.doc);
TResult p = new TResult();
p.id = (Long) hit.getField(StatusField.ID.name).numericValue();
p.screen_name = hit.get(StatusField.SCREEN_NAME.name);
p.epoch = (Long) hit.getField(StatusField.EPOCH.name).numericValue();
p.text = hit.get(StatusField.TEXT.name);
p.rsv = scoreDoc.score;
p.followers_count = (Integer) hit.getField(StatusField.FOLLOWERS_COUNT.name).numericValue();
p.statuses_count = (Integer) hit.getField(StatusField.STATUSES_COUNT.name).numericValue();
if ( hit.get(StatusField.LANG.name) != null) {
p.lang = hit.get(StatusField.LANG.name);
}
if ( hit.get(StatusField.IN_REPLY_TO_STATUS_ID.name) != null) {
p.in_reply_to_status_id = (Long) hit.getField(StatusField.IN_REPLY_TO_STATUS_ID.name).numericValue();
}
if ( hit.get(StatusField.IN_REPLY_TO_USER_ID.name) != null) {
p.in_reply_to_user_id = (Long) hit.getField(StatusField.IN_REPLY_TO_USER_ID.name).numericValue();
}
if ( hit.get(StatusField.RETWEETED_STATUS_ID.name) != null) {
p.retweeted_status_id = (Long) hit.getField(StatusField.RETWEETED_STATUS_ID.name).numericValue();
}
if ( hit.get(StatusField.RETWEETED_USER_ID.name) != null) {
p.retweeted_user_id = (Long) hit.getField(StatusField.RETWEETED_USER_ID.name).numericValue();
}
if ( hit.get(StatusField.RETWEET_COUNT.name) != null) {
p.retweeted_count = (Integer) hit.getField(StatusField.RETWEET_COUNT.name).numericValue();
}
results.add(p);
}
} catch (Exception e) {
e.printStackTrace();
throw new TrecSearchException(e.getMessage());
}
long endTime = System.currentTimeMillis();
LOG.info(String.format("%4dms %s", (endTime - startTime), query.toString()));