From 261fc6e085e91767d3c2dcfc674df10a6c5a9834 Mon Sep 17 00:00:00 2001 From: Elie Canonici Merle Date: Mon, 5 Aug 2024 15:37:23 +0200 Subject: [PATCH 1/4] use new persons_starting_with to generate person search list --- src/api_saisie_write.ml | 53 +++++++++++++++++++++++++++---- src/api_saisie_write.mli | 5 ++- src/api_search.ml | 31 ++++++++++-------- src/api_search.mli | 2 +- src/assets/api_saisie_write.proto | 1 + src/plugin_api.ml | 2 +- 6 files changed, 68 insertions(+), 26 deletions(-) diff --git a/src/api_saisie_write.ml b/src/api_saisie_write.ml index d94e563..b2479bd 100644 --- a/src/api_saisie_write.ml +++ b/src/api_saisie_write.ml @@ -23,14 +23,9 @@ let print_auto_complete assets conf base = let data = Api_saisie_write_piqi_ext.gen_auto_complete_result result in Api_util.print_result conf data - -let print_person_search_list conf base = - let params = Api_util.get_params conf Api_saisie_write_piqi_ext.parse_person_search_list_params in - let surname = params.Api_saisie_write_piqi.Person_search_list_params.lastname in - let first_name = params.Api_saisie_write_piqi.Person_search_list_params.firstname in - let max_res = Int32.to_int params.Api_saisie_write_piqi.Person_search_list_params.limit in +let print_person_search_list with_cut_at_max conf base first_name surname max_res = let list = - Api_search.search_person_list base surname first_name + Api_search.search_person_list conf base surname first_name (if with_cut_at_max then Some max_res else None) in let list = List.sort @@ -71,6 +66,50 @@ let print_person_search_list conf base = let data = Api_saisie_write_piqi_ext.gen_person_search_list result in Api_util.print_result conf data +let print_person_search_list' conf base first_name surname limit = + let first_name_prefix = Option.value first_name ~default:"" in + let surname_prefix = Option.value surname ~default:"" in + let persons = Geneweb.SearchName.persons_starting_with ~conf ~base ~first_name_prefix ~surname_prefix ~limit in + let list = List.map (fun p -> + Api_update_util.pers_to_piqi_person_search conf base p + ) persons in + let result = Api_saisie_write_piqi.Person_search_list.({ persons = list; }) in + let data = Api_saisie_write_piqi_ext.gen_person_search_list result in + Api_util.print_result conf data + +let print_person_search_list_hom conf base first_name surname limit = + let first_name = Option.value first_name ~default:"" in + let surname = Option.value surname ~default:"" in + let conf = {conf with Geneweb.Config.env = ("first_name", Adef.encoded first_name) :: ("surname", Adef.encoded surname) :: conf.Geneweb.Config.env} in + let persons = fst @@ Geneweb.AdvSearchOk.advanced_search conf base limit in + let list = List.map (fun p -> + Api_update_util.pers_to_piqi_person_search conf base p + ) persons in + let result = Api_saisie_write_piqi.Person_search_list.({ persons = list; }) in + let data = Api_saisie_write_piqi_ext.gen_person_search_list result in + Api_util.print_result conf data + +let get_person_search_list_parameters params = + let surname = params.Api_saisie_write_piqi.Person_search_list_params.lastname in + let first_name = params.Api_saisie_write_piqi.Person_search_list_params.firstname in + let limit = Int32.to_int params.Api_saisie_write_piqi.Person_search_list_params.limit in + let search_type = params.Api_saisie_write_piqi.Person_search_list_params.search_type in + first_name, surname, limit, search_type + +let print_person_search_list_switch conf base = + let params = Api_util.get_params conf Api_saisie_write_piqi_ext.parse_person_search_list_params in + let first_name, surname, limit, search_type = get_person_search_list_parameters params in + let f = match search_type with + | Some "searchtree" | None -> print_person_search_list false conf + | Some "searchtree-limited" -> print_person_search_list true conf + | Some "searchhom" -> print_person_search_list_hom conf + | Some "searchhom-pfx" -> + let conf = {conf with env = ("exact_first_name", Adef.encoded "pfx") :: ("exact_surname", Adef.encoded "pfx") :: conf.env} in + print_person_search_list_hom conf + | Some "searchtree-index" -> print_person_search_list' conf + | Some _s -> assert false + in + f base first_name surname limit let print_person_search_info conf base = let params = Api_util.get_params conf Api_saisie_write_piqi_ext.parse_index_person in diff --git a/src/api_saisie_write.mli b/src/api_saisie_write.mli index 27ee0b0..236f562 100644 --- a/src/api_saisie_write.mli +++ b/src/api_saisie_write.mli @@ -8,14 +8,13 @@ val print_auto_complete : string -> Geneweb.Config.config -> Gwdb.base -> unit - result : la liste de la recherche. *) -val print_person_search_list : Geneweb.Config.config -> Gwdb.base -> unit +val print_person_search_list_switch : Geneweb.Config.config -> Gwdb.base -> unit (** [Description] : Renvoie la liste des personnes qui ont ce nom ou prénom. [Args] : - conf : configuration de la base - base : base de donnée [Retour] : - - result : la liste de la recherche. - *) + - result : la liste de la recherche. *) val print_person_search_info : Geneweb.Config.config -> Gwdb.base -> unit (** [Description] : Affiche les informations telles que sur le panneau diff --git a/src/api_search.ml b/src/api_search.ml index 37664ed..2263880 100644 --- a/src/api_search.ml +++ b/src/api_search.ml @@ -364,11 +364,12 @@ let string_incl_start_with x y = in loop 0 -let select_both_start_with_person base ini_n ini_p = +let select_both_start_with_person conf base ini_n ini_p max = let find n x = string_start_with x n in let ini_n = aux_ini (Name.lower ini_n) in let ini_p = aux_ini (Name.lower ini_p) in - Gwdb.Collection.fold begin fun list p -> + let continue (n, _acc) = n < max in + Gwdb.Collection.fold_until continue begin fun (n, list) p -> let surnames = aux_ini (Name.lower (Gwdb.sou base (Gwdb.get_surname p))) in let first_names = aux_ini (Name.lower (Gwdb.sou base (Gwdb.get_first_name p))) in let start_surname = @@ -381,23 +382,24 @@ let select_both_start_with_person base ini_n ini_p = (fun ini -> List.exists (fun name -> find name ini) first_names) ini_p in - if start_surname && start_firstname then (Gwdb.get_iper p :: list) - else list - end [] (Gwdb.persons base) + if start_surname && start_firstname && Geneweb.Util.authorized_age conf base p then (n + 1, Gwdb.get_iper p :: list) + else (n, list) + end (0, []) (Gwdb.persons base) -let select_start_with_person base get_field ini = +let select_start_with_person conf base get_field ini max = let find n x = string_start_with x n in let ini = aux_ini (Name.lower ini) in - Gwdb.Collection.fold begin fun list p -> + let continue (n, _acc) = n < max in + Gwdb.Collection.fold_until continue begin fun (n, list) p -> let names = aux_ini (Name.lower (Gwdb.sou base (get_field p))) in let start_name = List.for_all (fun ini -> List.exists (fun name -> find name ini) names) ini in - if start_name then (Gwdb.get_iper p :: list) - else list - end [] (Gwdb.persons base) + if start_name && Geneweb.Util.authorized_age conf base p then (n + 1, Gwdb.get_iper p :: list) + else n, list + end (0, []) (Gwdb.persons base) let matching_nameset base stop max_res istr name_f name first_letter = let rec aux n istr set = @@ -661,8 +663,9 @@ let search_auto_complete assets conf base mode place_mode max term = complete_with_dico assets conf nb max (Some `profession) term suggestions_from_db -let search_person_list base surname first_name = +let search_person_list conf base surname first_name max_o = let _ = Gwdb.load_strings_array base in + let max = Option.value ~default:max_int max_o in let (surname, first_name) = match (surname, first_name) with | (Some n, Some fn) -> @@ -674,9 +677,9 @@ let search_person_list base surname first_name = in match (surname, first_name) with | (Some n, Some fn) -> - select_both_start_with_person base n fn + snd @@ select_both_start_with_person conf base n fn max | (Some n, None) -> - select_start_with_person base Gwdb.get_surname n + snd @@ select_start_with_person conf base Gwdb.get_surname n max | (None, Some fn) -> - select_start_with_person base Gwdb.get_first_name fn + snd @@ select_start_with_person conf base Gwdb.get_first_name fn max | (None, None) -> [] diff --git a/src/api_search.mli b/src/api_search.mli index 363deba..a69f9dd 100644 --- a/src/api_search.mli +++ b/src/api_search.mli @@ -35,4 +35,4 @@ val search_auto_complete : string list val search_person_list : - Gwdb.base -> string option -> string option -> Gwdb.iper list + Geneweb.Config.config -> Gwdb.base -> string option -> string option -> int option -> Gwdb.iper list diff --git a/src/assets/api_saisie_write.proto b/src/assets/api_saisie_write.proto index 9455009..82bb643 100644 --- a/src/assets/api_saisie_write.proto +++ b/src/assets/api_saisie_write.proto @@ -560,6 +560,7 @@ message PersonSearchListParams { optional string lastname = 1; optional string firstname = 2; required int32 limit = 3; + optional string search_type = 4; } message PersonSearchList { diff --git a/src/plugin_api.ml b/src/plugin_api.ml index da9e0d5..92a9262 100644 --- a/src/plugin_api.ml +++ b/src/plugin_api.ml @@ -127,7 +127,7 @@ let () = ; ( "API_GET_CONFIG" , aux @@ fun conf _ -> wiz' Plugin_api_lib.Api_saisie_write.print_config conf) ; ( "API_PERSON_SEARCH_LIST" - , aux @@ wiz @@ w_base @@ Plugin_api_lib.Api_saisie_write.print_person_search_list) + , aux @@ w_base @@ Plugin_api_lib.Api_saisie_write.print_person_search_list_switch) ; ( "API_GET_PERSON_SEARCH_INFO" , aux @@ wiz @@ w_base @@ Plugin_api_lib.Api_saisie_write.print_person_search_info) ; ( "API_ADD_CHILD" From 5b1c104e50f7703e89d40abe200bed773b94d4f6 Mon Sep 17 00:00:00 2001 From: Elie Canonici Merle Date: Mon, 23 Sep 2024 16:28:35 +0200 Subject: [PATCH 2/4] use search filter --- src/api_saisie_write.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api_saisie_write.ml b/src/api_saisie_write.ml index b2479bd..a3c4126 100644 --- a/src/api_saisie_write.ml +++ b/src/api_saisie_write.ml @@ -69,7 +69,7 @@ let print_person_search_list with_cut_at_max conf base first_name surname max_re let print_person_search_list' conf base first_name surname limit = let first_name_prefix = Option.value first_name ~default:"" in let surname_prefix = Option.value surname ~default:"" in - let persons = Geneweb.SearchName.persons_starting_with ~conf ~base ~first_name_prefix ~surname_prefix ~limit in + let persons = Geneweb.SearchName.persons_starting_with ~conf ~base ~filter:(fun _ -> true) ~first_name_prefix ~surname_prefix ~limit in let list = List.map (fun p -> Api_update_util.pers_to_piqi_person_search conf base p ) persons in From 70a28be50e59bbef041794290d98a0b9f739d1af Mon Sep 17 00:00:00 2001 From: Elie Canonici Merle Date: Mon, 30 Sep 2024 14:37:08 +0200 Subject: [PATCH 3/4] clean api search person --- src/api_saisie_write.ml | 92 +++++-------------------------- src/api_saisie_write.mli | 2 +- src/assets/api_saisie_write.proto | 1 - src/plugin_api.ml | 2 +- 4 files changed, 15 insertions(+), 82 deletions(-) diff --git a/src/api_saisie_write.ml b/src/api_saisie_write.ml index a3c4126..aabd3de 100644 --- a/src/api_saisie_write.ml +++ b/src/api_saisie_write.ml @@ -23,64 +23,20 @@ let print_auto_complete assets conf base = let data = Api_saisie_write_piqi_ext.gen_auto_complete_result result in Api_util.print_result conf data -let print_person_search_list with_cut_at_max conf base first_name surname max_res = - let list = - Api_search.search_person_list conf base surname first_name (if with_cut_at_max then Some max_res else None) - in - let list = - List.sort - (fun ip1 ip2 -> - let p1 = Gwdb.poi base ip1 in - let p2 = Gwdb.poi base ip2 in - let fn1 = Gwdb.sou base (Gwdb.get_first_name p1) in - let sn1 = Gwdb.sou base (Gwdb.get_surname p1) in - let fn2 = Gwdb.sou base (Gwdb.get_first_name p2) in - let sn2 = Gwdb.sou base (Gwdb.get_surname p2) in - let cmp_sn = Gutil.alphabetic_order sn1 sn2 in - if cmp_sn = 0 then - let cmp_fn = Gutil.alphabetic_order fn1 fn2 in - if cmp_fn = 0 then - (match - (Date.od_of_cdate (Gwdb.get_birth p1), - Date.od_of_cdate (Gwdb.get_birth p2)) - with - | (Some d1, Some d2) -> Date.compare_date d1 d2 - | (Some _, _) -> -1 - | (_, Some _) -> 1 - | (_, _) -> 0) - else cmp_fn - else cmp_sn) - list - in - (* On préfère limiter la liste ici, même si on perd un peu en performance. *) - let list = Geneweb.Util.reduce_list max_res list in - let () = Geneweb.SosaCache.build_sosa_ht conf base in - let list = - List.map - (fun ip -> - let p = Gwdb.poi base ip in - Api_update_util.pers_to_piqi_person_search conf base p) - list - in - let result = Api_saisie_write_piqi.Person_search_list.({ persons = list; }) in - let data = Api_saisie_write_piqi_ext.gen_person_search_list result in - Api_util.print_result conf data - -let print_person_search_list' conf base first_name surname limit = - let first_name_prefix = Option.value first_name ~default:"" in - let surname_prefix = Option.value surname ~default:"" in - let persons = Geneweb.SearchName.persons_starting_with ~conf ~base ~filter:(fun _ -> true) ~first_name_prefix ~surname_prefix ~limit in - let list = List.map (fun p -> - Api_update_util.pers_to_piqi_person_search conf base p - ) persons in - let result = Api_saisie_write_piqi.Person_search_list.({ persons = list; }) in - let data = Api_saisie_write_piqi_ext.gen_person_search_list result in - Api_util.print_result conf data - -let print_person_search_list_hom conf base first_name surname limit = - let first_name = Option.value first_name ~default:"" in +let print_person_search_list conf base = + let params = Api_util.get_params conf Api_saisie_write_piqi_ext.parse_person_search_list_params in + let surname = params.Api_saisie_write_piqi.Person_search_list_params.lastname in let surname = Option.value surname ~default:"" in - let conf = {conf with Geneweb.Config.env = ("first_name", Adef.encoded first_name) :: ("surname", Adef.encoded surname) :: conf.Geneweb.Config.env} in + let first_name = params.Api_saisie_write_piqi.Person_search_list_params.firstname in + let first_name = Option.value first_name ~default:"" in + + let limit = Int32.to_int params.Api_saisie_write_piqi.Person_search_list_params.limit in + let conf = {conf with Geneweb.Config.env = + ("first_name", Adef.encoded first_name) + :: ("surname", Adef.encoded surname) + :: ("exact_first_name", Adef.encoded "pfx") + :: ("exact_surname", Adef.encoded "pfx") + :: conf.env} in let persons = fst @@ Geneweb.AdvSearchOk.advanced_search conf base limit in let list = List.map (fun p -> Api_update_util.pers_to_piqi_person_search conf base p @@ -89,28 +45,6 @@ let print_person_search_list_hom conf base first_name surname limit = let data = Api_saisie_write_piqi_ext.gen_person_search_list result in Api_util.print_result conf data -let get_person_search_list_parameters params = - let surname = params.Api_saisie_write_piqi.Person_search_list_params.lastname in - let first_name = params.Api_saisie_write_piqi.Person_search_list_params.firstname in - let limit = Int32.to_int params.Api_saisie_write_piqi.Person_search_list_params.limit in - let search_type = params.Api_saisie_write_piqi.Person_search_list_params.search_type in - first_name, surname, limit, search_type - -let print_person_search_list_switch conf base = - let params = Api_util.get_params conf Api_saisie_write_piqi_ext.parse_person_search_list_params in - let first_name, surname, limit, search_type = get_person_search_list_parameters params in - let f = match search_type with - | Some "searchtree" | None -> print_person_search_list false conf - | Some "searchtree-limited" -> print_person_search_list true conf - | Some "searchhom" -> print_person_search_list_hom conf - | Some "searchhom-pfx" -> - let conf = {conf with env = ("exact_first_name", Adef.encoded "pfx") :: ("exact_surname", Adef.encoded "pfx") :: conf.env} in - print_person_search_list_hom conf - | Some "searchtree-index" -> print_person_search_list' conf - | Some _s -> assert false - in - f base first_name surname limit - let print_person_search_info conf base = let params = Api_util.get_params conf Api_saisie_write_piqi_ext.parse_index_person in let ip = Gwdb.iper_of_string @@ Int32.to_string params.Api_saisie_write_piqi.Index_person.index in diff --git a/src/api_saisie_write.mli b/src/api_saisie_write.mli index 236f562..a66f4e8 100644 --- a/src/api_saisie_write.mli +++ b/src/api_saisie_write.mli @@ -8,7 +8,7 @@ val print_auto_complete : string -> Geneweb.Config.config -> Gwdb.base -> unit - result : la liste de la recherche. *) -val print_person_search_list_switch : Geneweb.Config.config -> Gwdb.base -> unit +val print_person_search_list : Geneweb.Config.config -> Gwdb.base -> unit (** [Description] : Renvoie la liste des personnes qui ont ce nom ou prénom. [Args] : - conf : configuration de la base diff --git a/src/assets/api_saisie_write.proto b/src/assets/api_saisie_write.proto index 82bb643..9455009 100644 --- a/src/assets/api_saisie_write.proto +++ b/src/assets/api_saisie_write.proto @@ -560,7 +560,6 @@ message PersonSearchListParams { optional string lastname = 1; optional string firstname = 2; required int32 limit = 3; - optional string search_type = 4; } message PersonSearchList { diff --git a/src/plugin_api.ml b/src/plugin_api.ml index 92a9262..9bc3b8b 100644 --- a/src/plugin_api.ml +++ b/src/plugin_api.ml @@ -127,7 +127,7 @@ let () = ; ( "API_GET_CONFIG" , aux @@ fun conf _ -> wiz' Plugin_api_lib.Api_saisie_write.print_config conf) ; ( "API_PERSON_SEARCH_LIST" - , aux @@ w_base @@ Plugin_api_lib.Api_saisie_write.print_person_search_list_switch) + , aux @@ w_base @@ Plugin_api_lib.Api_saisie_write.print_person_search_list) ; ( "API_GET_PERSON_SEARCH_INFO" , aux @@ wiz @@ w_base @@ Plugin_api_lib.Api_saisie_write.print_person_search_info) ; ( "API_ADD_CHILD" From d54b55b850941bdfa6535906210f29fc63e87084 Mon Sep 17 00:00:00 2001 From: Elie Canonici Merle Date: Mon, 14 Oct 2024 09:42:08 +0200 Subject: [PATCH 4/4] sort search results --- src/api_saisie_write.ml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/api_saisie_write.ml b/src/api_saisie_write.ml index aabd3de..b0b0504 100644 --- a/src/api_saisie_write.ml +++ b/src/api_saisie_write.ml @@ -38,6 +38,18 @@ let print_person_search_list conf base = :: ("exact_surname", Adef.encoded "pfx") :: conf.env} in let persons = fst @@ Geneweb.AdvSearchOk.advanced_search conf base limit in + let cmp_per p1 p2 = + let c1 = String.compare + (Gwdb.sou base (Gwdb.get_surname p1)) + (Gwdb.sou base (Gwdb.get_surname p2)) + in + if c1 = 0 then + String.compare + (Gwdb.sou base (Gwdb.get_first_name p1)) + (Gwdb.sou base (Gwdb.get_first_name p2)) + else c1 + in + let persons = List.sort cmp_per persons in let list = List.map (fun p -> Api_update_util.pers_to_piqi_person_search conf base p ) persons in