Date fields in pack
This commit is contained in:
parent
0b6a8dd298
commit
da83caa8da
@ -6,9 +6,21 @@ let of_set field t =
|
||||
let add x a = Msgpck.String x :: a in
|
||||
List.rev @@ String_set.fold add (Text.set field t) []
|
||||
|
||||
let date = function
|
||||
| None -> Int32.zero
|
||||
| Some date ->
|
||||
let days, ps = Ptime.Span.to_d_ps (Ptime.to_span date) in
|
||||
Int32.add Int32.(mul (of_int days) 86400l) Int64.(to_int32 (div ps 1000000000000L))
|
||||
|
||||
let columns = Msgpck.(List
|
||||
[String "id"; String "time"; String "title";
|
||||
String "authors"; String "topics"; String "keywords"])
|
||||
|
||||
let to_pack a t =
|
||||
let open Text in
|
||||
Msgpck.(List [Bytes (Id.to_bytes t.uuid); String t.title; List (persons t.authors);
|
||||
Msgpck.(List [Bytes (Id.to_bytes t.uuid);
|
||||
of_uint32 (date (Date.listing t.date));
|
||||
String t.title; List (persons t.authors);
|
||||
List (of_set "topics" t); List (of_set "keywords" t)]) :: a
|
||||
|
||||
let pack_filename ?(filename="index.pck") archive =
|
||||
@ -28,15 +40,12 @@ let list filename = try
|
||||
with Not_found -> Error "unspecified export dir"
|
||||
|
||||
let contains text = function
|
||||
| Msgpck.List (id::title::_authors::_topics::_keywords) ->
|
||||
| Msgpck.List (id::_time::title::_authors::_topics::_keywords) ->
|
||||
(match Id.of_bytes (Msgpck.to_bytes id) with
|
||||
| None -> prerr_endline ("Invalid id for " ^ Msgpck.to_string title); false
|
||||
| Some id -> text.Text.uuid = id)
|
||||
| _ -> prerr_endline ("Invalid record pattern"); false
|
||||
|
||||
let columns = Msgpck.(List [String "id"; String "title"; String "authors";
|
||||
String "topics"; String "keywords"])
|
||||
|
||||
let pack archive records =
|
||||
let header_pack = List.fold_left to_pack [] records in
|
||||
let archive = Msgpck.(List [Int 0; String archive.File_store.name;
|
||||
|
Loading…
x
Reference in New Issue
Block a user