MCPcopy Create free account
hub / github.com/internetarchive/openlibrary / process_facet

Function process_facet

openlibrary/plugins/worksearch/code.py:265–284  ·  view source on GitHub ↗
(field: str, facets: Iterable[tuple[str, int]])

Source from the content-addressed store, hash-verified

263
264
265def process_facet(field: str, facets: Iterable[tuple[str, int]]) -> tuple[str, str, int]:
266 if field == "has_fulltext":
267 counts = dict(facets)
268 yield ("true", "yes", counts.get("true", 0))
269 yield ("false", "no", counts.get("false", 0))
270 else:
271 for val, count in facets:
272 if count == 0:
273 continue
274 if field == "author_key":
275 key, name = read_author_facet(val)
276 yield (key, name, count)
277 elif field == "language":
278 yield (
279 val,
280 get_language_name(f"/languages/{val}", req_context.get().lang or "en"),
281 count,
282 )
283 else:
284 yield (val, val, count)
285
286
287def process_facet_counts(

Callers 2

test_process_facetFunction · 0.90
process_facet_countsFunction · 0.85

Calls 3

get_language_nameFunction · 0.90
read_author_facetFunction · 0.85
getMethod · 0.45

Tested by 1

test_process_facetFunction · 0.72