From a7a62ca016abca387ba9e9ffb7393aed984b2ce1 Mon Sep 17 00:00:00 2001 From: tim b Date: Sun, 26 Sep 2010 17:17:54 -0700 Subject: made javascript callback for search optional to make browser not freeze while fetching search results on dump --- src/site.clj | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/site.clj b/src/site.clj index e38020a..f88afaf 100644 --- a/src/site.clj +++ b/src/site.clj @@ -1000,23 +1000,36 @@ WHERE u.user_id = ANY(?)" favs (reduce (fn [m fav] (assoc m (str (fav :message_id)) (fav :content))) {} raw-favs)] (str "RawFavs=" (json-str favs)))) -(defn ghetto-search-query [num-tokens] +(defn search-query [num-tokens] (str "select url from image_urls where url ilike " (str-join " and url ilike " (take num-tokens (repeat "?"))) " order by last_posted desc limit 200;")) -(def *ghetto-search-regex* #"^[A-Za-z0-9\-_.+]*$") +;; note: _ is a wildcard in a postgres 'like' query... +(defn search-replace-weird-chars [token] + (str (.replaceAll token "[^A-Za-z0-9\\-.=+]" "_")) +) + +;; timb: this can be called with a callback or not... +;; +;; dump.fm/cmd/search/foo -> [result, result] +;; cons: can only be ajax get'd from the same domain +;; +;; dump.fm/cmd/search/foo?callback=someFunc -> someFunc([result, result]) +;; cons: has to use a