         [:.created (document/format-datetime modified)])
       (om/build tags/tags-list (:tags document))]]))
 
+(defn- run-search! [search owner]
+  (if-let [query (search/parse-query-string search)]
+    (async/take! (api/search-documents query)
+                 (fn [documents]
+                   (println "Found documents:" documents)
+                   (om/set-state! owner :documents documents)))
+    (om/set-state! owner :documents nil))
+  ;; Set the node's value to the right string
+  (when-let [node (om/get-node owner "search")]
+    (set! (.-value node) search)))
+
 (ui/defcomponent search-ui [[state column] owner]
-  (will-update [_ next-props next-state]
+  (will-mount [_]
+    ;; Run search (if we have a search string in the url)
+    (when-let [search (:search column)]
+      (run-search! search owner)))
+  (will-update [_ [next-props next-column] next-state]
+    ;; Run search if the search-string changes (note that an empty or
+    ;; nil search-string is fine and will just clear the results)
+    (let [search (:search next-column)]
+      (when-not (= search (:search column))
+        (run-search! search owner)))
+    ;; Fetch documents after the results of the search arrive
     (when-let [documents (:documents next-state)]
-      (when-not (= documents  (om/get-render-state owner :documents))
+      (when-not (= documents (om/get-render-state owner :documents))
+        ;; TODO: Only fetch documents we don't have locally
         (api/fetch-documents! documents))))
   (render-state [_ {:keys [documents]}]
     [:.column.search

      [:form {:on-submit (fn [e]
                           (ui/cancel-event e)
                           (let [text (.-value (om/get-node owner "search"))
                                 query (search/parse-query-string text)]
                             (if query
                               (async/take! (api/search-documents query)
                                            (fn [documents]
                                              (println "Found documents:" documents)
                                              (om/set-state! owner :documents documents)))
                               (om/set-state! owner :documents nil))))}
       [:input.search {:type "text"
                       :ref "search"
                       :placeholder "Search Documents"}]
       [:button {:type "submit"}
        "Search"]]]
     [:ul.search-results
      (om/build-all search-result-row (map #(get-in state [:documents %]) documents)
                    {:opts {:on-click (fn [document]
                                        (let [columns (->> (current-columns state)
                                                           (remove #(= % [:search nil])))]
                                          (add-column! columns [:document (:id document)])))}})]]))

(defn ^:private inbox-handle-drop! [state owner page-cache target source page-ids target-idx]

                        [[:document id]]    (->DocumentColumnSource (.getNextUniqueId gen) id)
                        [[:inbox _]]        (->InboxColumnSource (.getNextUniqueId gen))
                        [[:new-document _]] (->NewDocumentColumn (.getNextUniqueId gen))
                        [[:search s]]       (->SearchColumn (.getNextUniqueId gen) s)))]
        (filterv identity columns)))))

(defn- prepare-columns! [props state owner]
