From: Stefano Zacchiroli Date: Thu, 6 Mar 2003 16:14:24 +0000 (+0000) Subject: - parse postgres connection string also from environment variable X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=5a80860a63d656e3737f9ad383b300166cdecaa9;p=helm.git - parse postgres connection string also from environment variable - solved some compatibility issues with MathQL - use old Misc functions from MQueryMisc --- diff --git a/helm/searchEngine/searchEngine.ml b/helm/searchEngine/searchEngine.ml index 7e859775a..15fb92de7 100644 --- a/helm/searchEngine/searchEngine.ml +++ b/helm/searchEngine/searchEngine.ml @@ -29,6 +29,13 @@ Http_common.debug := true;; open Printf;; +let postgresConnectionString = + try + Sys.getenv "POSTGRESQL_CONNECTION_STRING" + with + Not_found -> "host=mowgli.cs.unibo.it dbname=helm_mowgli_new_schema user=helm" +;; + let daemon_name = "Search Engine";; let default_port = 58085;; let port_env_var = "SEARCH_ENGINE_PORT";; @@ -40,6 +47,14 @@ let final_results_TPL = pages_dir ^ "/templateambigpdq3.html";; exception Chat_unfinished + (** pretty print a MathQL query result to a string *) +let text_of_result result sep = + let res_string = ref "" in + let app = function s -> res_string := !res_string ^ s in + MQueryUtil.text_of_result app result sep ; + !res_string +;; + (** chain application of Pcre substitutions *) let rec apply_substs substs line = match substs with @@ -77,9 +92,9 @@ let port = default_port in let pp_result result = - let result_string = MQueryUtil.text_of_result result "\n" in + let res_string = text_of_result result "\n" in (sprintf "\n\n\n\n
%s
\n\n" - result_string) + res_string) in let pp_error = sprintf "

Error: %s

" in let bad_request body outchan = @@ -102,7 +117,7 @@ let callback (req: Http_types.request) outchan = let lexbuf = Lexing.from_string query_string in let query = MQueryUtil.query_of_text lexbuf in let result = MQueryGenerator.execute_query query in - let result_string = MQueryUtil.text_of_result result "\n" in + let result_string = text_of_result result "\n" in Http_daemon.respond ~body: (sprintf "
%s
" result_string) @@ -119,7 +134,7 @@ let callback (req: Http_types.request) outchan = match page with | page when is_permitted page -> Http_daemon.respond_file - ~fname:(sprintf "%s/%s" pages_dir page) outchan + ~fname:(sprintf "%s/%s" pages_dir (remove_fragment page)) outchan | page -> Http_daemon.respond_forbidden ~url:page outchan) | "/searchPattern" -> let term_string = req#param "term" in @@ -138,7 +153,7 @@ let callback (req: Http_types.request) outchan = (key::keys) (fun id -> if id = key then - Some (Disambiguate.cic_textual_parser_uri_of_string value) + Some (MQueryMisc.cic_textual_parser_uri_of_string value) else lookup id) rest | _ -> failwith "Can't parse aliases" @@ -226,7 +241,7 @@ let callback (req: Http_types.request) outchan = (fun (id, value) -> (sprintf "alias %s %s" id - (Disambiguate.wrong_xpointer_format_from_wrong_xpointer_format' + (MQueryMisc.wrong_xpointer_format_from_wrong_xpointer_format' value))) l)) ^ "\"") @@ -272,13 +287,13 @@ let callback (req: Http_types.request) outchan = (match f name with | None -> assert false | Some t -> - Disambiguate.string_of_cic_textual_parser_uri + MQueryMisc.string_of_cic_textual_parser_uri t)) domain) in let processed_line = apply_substs - [results_RE, MQueryUtil.text_of_result results "\n"; + [results_RE, text_of_result results "\n"; new_aliases_RE, new_aliases] line in @@ -307,7 +322,7 @@ printf "current directory is %s\n" (Sys.getcwd ()); flush stdout; Unix.putenv "http_proxy" ""; Mqint.set_database Mqint.postgres_db; -Mqint.init "host=mowgli.cs.unibo.it dbname=helm_mowgli_new_schema user=helm"; +Mqint.init postgresConnectionString; Http_daemon.start' ~port callback; Mqint.close (); printf "%s is terminating, bye!\n" daemon_name