• R/O
  • SSH
  • HTTPS

nt-manager: Commit


Commit MetaInfo

Revision171 (tree)
Time2011-08-24 03:26:19
Authorspark_xp

Log Message

ツイート検索にStreaming APIを使ったものを作った #24964

Change Summary

Incremental Difference

--- NishioTweetManager/trunk/src/twitter/manage/TweetSearchStream.java (revision 170)
+++ NishioTweetManager/trunk/src/twitter/manage/TweetSearchStream.java (revision 171)
@@ -41,6 +41,8 @@
4141 private TweetManager tweetManager = null;
4242 //検索ワードに対応したリスナー
4343 private Map<String, TweetStreamingListener> listeners = null;
44+ //指定したワードの最終更新id
45+ private Map<String, Long> lastUpdate = null;
4446
4547 /**
4648 *
@@ -58,6 +60,7 @@
5860 filter = new FilterQuery();
5961 filterWords = new HashSet<String>();
6062 listeners = new HashMap<String, TweetStreamingListener>();
63+ lastUpdate = new HashMap<String, Long>();
6164 }
6265
6366 /**
@@ -106,12 +109,26 @@
106109 if( status.getText().contains( word.toString() ) ) {
107110 TweetStreamingListener listener = listeners.get(word);
108111 listener.update(status);
112+ //最終更新id
113+ lastUpdate.put(word, status.getId());
109114 }
110- System.out.println("WORD:" + word + " searching -- " + status.getText());
111115 }
112116 }
113117
114118 /**
119+ * 最終更新ステータスのidの取得
120+ * @param word
121+ * @return
122+ */
123+ public long getLastUpdateID(String word) {
124+ Long id = lastUpdate.get(word);
125+ if( id == null ) {
126+ return 0;
127+ }
128+ return id;
129+ }
130+
131+ /**
115132 *
116133 */
117134 @Override
--- NishioTweetManager/trunk/src/twitter/manage/TweetUserStreamManager.java (revision 170)
+++ NishioTweetManager/trunk/src/twitter/manage/TweetUserStreamManager.java (revision 171)
@@ -84,4 +84,13 @@
8484 public void stopSearchListener(String word) {
8585 searchStream.removeSearchWord(word);
8686 }
87+
88+ /**
89+ * 指定したワードの最終更新status IDを取得
90+ * @param word
91+ * @return
92+ */
93+ public long getSearchLastUpdateID(String word) {
94+ return searchStream.getLastUpdateID(word);
95+ }
8796 }
--- NishioTweetManager/trunk/src/twitter/action/TweetSearchResultGetter.java (revision 170)
+++ NishioTweetManager/trunk/src/twitter/action/TweetSearchResultGetter.java (revision 171)
@@ -58,6 +58,12 @@
5858 * @return
5959 */
6060 public List<Status> getNewTweetData() {
61+ //streaming利用時のsinceidを取得
62+ long streamingSinceID = tweetManager.getStreamManager().getSearchLastUpdateID(this.searchWord);
63+ if( streamingSinceID > 0 ) {
64+ sinceID = streamingSinceID;
65+ }
66+
6167 List<Status> status = tweetManager.getNewSearchResult(this.sinceID, this.searchWord);
6268 if( status != null ) {
6369 //一番最後のtweetのsinceIDを取得する
Show on old repository browser