ocaml
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Server: restore mistakenly deleted search handler

Some work needs to be done to make it usable

+36 -2
+36 -2
lib/server/Server.ml
··· 128 128 respond_html ~status:`OK ~body () 129 129 end 130 130 131 + let search_handler ~(request : Http.Request.t) ~forest ~body = 132 + if request.meth = `POST then 133 + let body = Eio.Flow.read_all body in 134 + let get_param key = 135 + Option.map (String.concat "") 136 + @@ Option.map snd 137 + @@ List.find_opt (fun (s, _) -> s = key) (Uri.query_of_encoded body) 138 + in 139 + let _search_term = Option.value ~default:"" @@ get_param "search" in 140 + let search_for = get_param "search-for" in 141 + let search_results = 142 + match search_for with 143 + | None -> [] 144 + | Some "title-text" -> 145 + (* Forester_search.Index.search *) 146 + (* forest.search_index *) 147 + (* search_term *) 148 + [] 149 + | Some "full-text" -> 150 + (* Forester_search.Index.search *) 151 + (* forest.search_index *) 152 + (* search_term *) 153 + [] 154 + | Some _ -> assert false 155 + in 156 + let env = Env.default ~forest in 157 + Search_menu.results ~env (List.map snd search_results) 158 + else "" 159 + 131 160 let handler : 132 161 env:< fs : [> Eio.Fs.dir_ty] Eio.Path.t ; .. > -> 133 162 forest:State.t option ref -> ··· 135 164 Http.Request.t -> 136 165 Cohttp_eio.Body.t -> 137 166 Cohttp_eio.Server.response = 138 - fun ~env ~forest _socket request _body -> 167 + fun ~env ~forest _socket request request_body -> 139 168 let resource = Uri.of_string request.resource in 140 169 let path = Uri.path resource in 141 170 let request_headers = Http.Request.headers request in ··· 160 189 | Home -> 161 190 tree_handler ~forest ~headers:request_headers 162 191 (URI.path_string forest.config.home) 163 - | Search -> Cohttp_eio.Server.respond_string ~body:"" ~status:`OK () 192 + | Search -> 193 + let status = 194 + if not (request.meth = `POST) then `OK else `Method_not_allowed 195 + in 196 + let body = search_handler ~request ~forest ~body:request_body in 197 + Cohttp_eio.Server.respond_string ~body ~status () 164 198 | Query -> query_handler ~forest ~resource 165 199 end 166 200 end