Skip to content

Commit 84cffaa

Browse files
committed
percolation matching working
1 parent bbd43cf commit 84cffaa

File tree

1 file changed

+9
-7
lines changed
  • Clojure-Websockets/src/clj/birdwatch

1 file changed

+9
-7
lines changed

Clojure-Websockets/src/clj/birdwatch/main.clj

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,15 @@
5555
(def chsk-send! send-fn) ; ChannelSocket's send API fn
5656
(def connected-uids connected-uids)) ; Watchable, read-only atom
5757

58+
(def subscriptions (atom {}))
5859

5960
(defn start-percolator [params]
61+
"register percolation search with ID based on hash of the query"
6062
(let [q (:query params)
61-
sha (sha1 (str q))]
62-
(perc/register-query conn "percolator" sha :query q) ; register percolation search with ID based on hash of the query
63+
sha (sha1 (str q))
64+
uid (:uid params)]
65+
(swap! subscriptions assoc uid sha)
66+
(perc/register-query conn "percolator" sha :query q)
6367
(log/info "Percolation registered for query" q "with SHA1" sha)))
6468

6569
(defn query [params]
@@ -183,11 +187,9 @@
183187
(let [t (<! tweets-chan)]
184188
(let [response (perc/percolate conn "percolator" "tweet" :doc t)
185189
matches (into #{} (map #(:_id %1) (esrsp/matches-from response)))]
186-
(log/info "esrsp/matches-from" matches))
187-
188-
(doseq [uid (:any @connected-uids)]
189-
(chsk-send! uid [:tweet/new t]))
190-
190+
(doseq [uid (:any @connected-uids)]
191+
(when (contains? matches (get @subscriptions uid))
192+
(chsk-send! uid [:tweet/new t]))))
191193
(try
192194
(esd/put conn (:es-index twitter-conf) "tweet" (:id_str t) t)
193195
(catch Exception ex (log/error ex "esd/put error"))))))

0 commit comments

Comments
 (0)