From 3a2434e94359e6376566ad6f8eaffb157cb54389 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 29 Oct 2018 18:17:01 -0400 Subject: [PATCH] bib search api wip Signed-off-by: Bill Erickson --- .../eg2/src/app/share/catalog/catalog.service.ts | 64 +++++++++++++--------- .../lib/OpenILS/Application/Search/Elastic.pm | 6 +- 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/catalog/catalog.service.ts b/Open-ILS/src/eg2/src/app/share/catalog/catalog.service.ts index bf6036ced6..a379098f3b 100644 --- a/Open-ILS/src/eg2/src/app/share/catalog/catalog.service.ts +++ b/Open-ILS/src/eg2/src/app/share/catalog/catalog.service.ts @@ -232,37 +232,19 @@ export class CatalogService { return Promise.resolve(); } + if (ctx.result.facets) { + // No need to fetch pre-compiled facets + console.debug('Showing pre-compiled facets'); + ctx.result.facetData = this.formatFacets(ctx.result.facets); + return Promise.resolve(); + } + return new Promise((resolve, reject) => { this.net.request('open-ils.search', 'open-ils.search.facet_cache.retrieve', ctx.result.facet_key ).subscribe(facets => { - const facetData = {}; - Object.keys(facets).forEach(cmfId => { - const facetHash = facets[cmfId]; - const cmf = this.cmfMap[cmfId]; - - const cmfData = []; - Object.keys(facetHash).forEach(value => { - const count = facetHash[value]; - cmfData.push({value : value, count : count}); - }); - - if (!facetData[cmf.field_class()]) { - facetData[cmf.field_class()] = {}; - } - - facetData[cmf.field_class()][cmf.name()] = { - cmfLabel : cmf.label(), - valueList : cmfData.sort((a, b) => { - if (a.count > b.count) { return -1; } - if (a.count < b.count) { return 1; } - // secondary alpha sort on display value - return a.value < b.value ? -1 : 1; - }) - }; - }); - + const facetData = this.formatFacets(facets); this.lastFacetKey = ctx.result.facet_key; this.lastFacetData = ctx.result.facetData = facetData; resolve(); @@ -270,6 +252,36 @@ export class CatalogService { }); } + formatFacets(facets: any) { + const facetData = {}; + Object.keys(facets).forEach(cmfId => { + const facetHash = facets[cmfId]; + const cmf = this.cmfMap[cmfId]; + + const cmfData = []; + Object.keys(facetHash).forEach(value => { + const count = facetHash[value]; + cmfData.push({value : value, count : count}); + }); + + if (!facetData[cmf.field_class()]) { + facetData[cmf.field_class()] = {}; + } + + facetData[cmf.field_class()][cmf.name()] = { + cmfLabel : cmf.label(), + valueList : cmfData.sort((a, b) => { + if (a.count > b.count) { return -1; } + if (a.count < b.count) { return 1; } + // secondary alpha sort on display value + return a.value < b.value ? -1 : 1; + }) + }; + }); + + return facetData; + } + fetchCcvms(): Promise { if (Object.keys(this.ccvmMap).length) { diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Elastic.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Elastic.pm index fbc34605ab..f2f1b6e0a1 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Elastic.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Elastic.pm @@ -59,7 +59,6 @@ sub bib_search { return {count => 0} unless $results; - format_facets($results->{aggregations}); return { count => $results->{hits}->{total}, @@ -67,7 +66,7 @@ sub bib_search { map { [$_->{_id}, undef, $_->{_score}] } grep {defined $_} @{$results->{hits}->{hits}} ], - facets => $results->{aggregations}, + facets => format_facets($results->{aggregations}), # Note at time of writing no search caching is used for # Elasticsearch, but providing cache keys allows the caller to # know if this search matches another search. @@ -83,7 +82,8 @@ sub format_facets { for my $fname (keys %$aggregations) { - my ($name, $field_class) = split('|', $fname); + my ($field_class, $name) = split(/\|/, $fname); + my ($bib_field) = grep { $_->name eq $name && $_->search_group eq $field_class } @$bib_search_fields; -- 2.11.0