source: code/trunk/lib/archive.ml@ 47

Last change on this file since 47 was 37, checked in by fox, 2 years ago

Partially matching ID queries

File size: 1.5 KB
Line 
1let predicate fn opt = Option.(to_list @@ map fn opt)
2
3let authored query_string =
4 let q = Person.Set.of_query @@ String_set.query query_string in
5 fun n -> Person.Set.predicate q n.Text.authors
6
7let ided query_string =
8 let len = String.length query_string in
9 fun n ->
10 try String.sub n.Text.id 0 len = query_string
11 with Invalid_argument _ -> false
12
13let keyworded query_string =
14 let q = String_set.query query_string in
15 fun n -> String_set.(predicate q (Text.set "Keywords" n))
16
17let topics query_string =
18 let q = String_set.query query_string in
19 fun n -> String_set.(predicate q (Text.set "Topics" n))
20
21let apply_sys_util env def_env r order_opt reverse_opt number_opt authors_opt topics_opt id_opt =
22 let predicates = if id_opt <> "" then [ ided id_opt ] else []
23 @ predicate authored authors_opt
24 @ predicate topics topics_opt in
25 let predicate text = List.fold_left (fun a e -> a && e text) true predicates in
26 let util = try Sys.getenv env with Not_found -> def_env in
27 let print_text acc (_t, fnames) = Printf.sprintf "%s %s" acc (List.hd fnames) in
28 let paths = match order_opt with
29 | false -> File_store.fold ~r ~predicate print_text ""
30 | true ->
31 let order = match reverse_opt with true -> File_store.newest | false -> File_store.oldest in
32 match number_opt with
33 | Some number -> File_store.fold ~r ~predicate ~order ~number print_text ""
34 | None -> File_store.fold ~r ~predicate ~order print_text ""
35 in if paths = "" then ()
36 else (ignore @@ Sys.command @@ Printf.sprintf "%s %s" util paths)
Note: See TracBrowser for help on using the repository browser.