···8686 let txt = Text.of_doc doc in
8787 `String txt
88888989-let of_entry ({ Entry.id; doc; kind } as entry) html =
8989+let of_entry ({ Entry.id; doc; kind } as entry) html occurrences =
9090 let j_id = of_id id in
9191 let doc = of_doc doc in
9292 let kind =
···167167 ("parent_type", `String (Text.of_type parent_type));
168168 ]
169169 in
170170+ let occurrences =
171171+ match occurrences with
172172+ | Some occ ->
173173+ `Object
174174+ [
175175+ ("direct", `Float (float_of_int occ.Odoc_occurrences.Table.direct));
176176+ ("indirect", `Float (float_of_int occ.indirect));
177177+ ]
178178+ | None -> `Null
179179+ in
170180 match Json_display.of_entry entry html with
171181 | Result.Ok display ->
172182 Result.Ok
173183 (`Object
174174- [ ("id", j_id); ("doc", doc); ("kind", kind); ("display", display) ])
184184+ [
185185+ ("id", j_id);
186186+ ("doc", doc);
187187+ ("kind", kind);
188188+ ("display", display);
189189+ ("occurrences", occurrences);
190190+ ])
175191 | Error _ as e -> e
176192177193let output_json ppf first entries =
···180196 Format.fprintf ppf "%s\n" str
181197 in
182198 List.fold_left
183183- (fun first (entry, html) ->
184184- let json = of_entry entry html in
199199+ (fun first (entry, html, occurrences) ->
200200+ let json = of_entry entry html occurrences in
185201 if not first then Format.fprintf ppf ",";
186202 match json with
187203 | Ok json ->
···192208 true)
193209 first entries
194210195195-let unit ppf u =
211211+let unit ?occurrences ppf u =
212212+ let get_occ id =
213213+ match occurrences with
214214+ | None -> None
215215+ | Some occurrences -> Odoc_occurrences.Table.get occurrences id
216216+ in
196217 let f first i =
197218 let entries = Entry.entries_of_item i in
198219 let entries =
199199- List.map (fun entry -> (entry, Html.of_entry entry)) entries
220220+ List.map
221221+ (fun entry ->
222222+ let occ = get_occ entry.Entry.id in
223223+ (entry, Html.of_entry entry, occ))
224224+ entries
200225 in
201226 let first = output_json ppf first entries in
202227 first
···208233 let f first i =
209234 let entries = Entry.entries_of_item i in
210235 let entries =
211211- List.map (fun entry -> (entry, Html.of_entry entry)) entries
236236+ List.map (fun entry -> (entry, Html.of_entry entry, None)) entries
212237 in
213238 output_json ppf first entries
214239 in
···219244 let _first =
220245 Odoc_model.Paths.Identifier.Hashtbl.Any.fold
221246 (fun _id entry first ->
222222- let entry = (entry, Html.of_entry entry) in
247247+ let entry = (entry, Html.of_entry entry, None) in
223248 output_json ppf first [ entry ])
224249 index true
225250 in
+5-1
src/search/json_index/json_search.mli
···11(** This module generates json intended to be consumed by search engines. *)
2233-val unit : Format.formatter -> Odoc_model.Lang.Compilation_unit.t -> unit
33+val unit :
44+ ?occurrences:Odoc_occurrences.Table.t ->
55+ Format.formatter ->
66+ Odoc_model.Lang.Compilation_unit.t ->
77+ unit
48val page : Format.formatter -> Odoc_model.Lang.Page.t -> unit
59val index :
610 Format.formatter ->