* another burst of search "pushes" the new search with the updated status
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
SearchNTT currentSearch = null;
/*
* if (req.getParameterMap().containsKey(CURRENT_SEARCH)) { Long id =
* Long.parseLong(req.getParameter(CURRENT_SEARCH)); currentSearch =
* DALService.ofy().get(SearchNTT.class, id); } else { String hashtag =
* req.getParameter(HASHTAG); currentSearch = new SearchNTT(hashtag); }
*/
currentSearch = popSearch();
if (currentSearch != null) {
logger.warning("-- Searching for " + currentSearch.getHashtag());
Twitter twitter = TwitterFactory.getSingleton();
Query query = new Query(currentSearch.getHashtag());
query.setCount(100);
//max o since?
//that is
//older than or newer than?
if (currentSearch.isFirstScan())
query.setMaxId(currentSearch.getMaxID());
else
query.setSinceId(currentSearch.getSinceID());
QueryResult result;
try {
result = twitter.search(query);
int size = result.getTweets().size();
logger.warning("-- Going to iterate on "+ size + " tweets");
if (size==0) {
logger.warning("-- REACHED "+ size + " tweets");
return;
}
else if(size==1)
{
logger.warning("-- REACHED "+ size + " tweets");
currentSearch.setFirstScan(false);
pushSearch(currentSearch);
return;
}
List<Status> tweets = result.getTweets();
for (Status tweet : tweets) {
System.out.println("@" + tweet.getUser().getScreenName()
+ " - " + tweet.getText());
logger.warning("-- "+ tweet.getText());
TweetNTT t = new TweetNTT(tweet);
DALService.ofy().put(t);
// need to keep track of minimum and maximum id
long tweetid = tweet.getId();
if (tweetid < currentSearch.getMaxID())
currentSearch.setMaxID(tweetid);
if (tweetid >= currentSearch.getSinceID())
currentSearch.setSinceID(tweetid);
}
logger.warning("-- Storing search "+currentSearch.getHashtag());
pushSearch(currentSearch);
} catch (TwitterException e) {
e.printStackTrace();
} catch (Exception e) {