kumovega-instantsearch-adapter
Version:
Adapter to use InstantSearch UI widgets with Kumovega Search
39 lines (31 loc) • 1.12 kB
JavaScript
;
import { utils } from "./support/utils";
export class FacetSearchResponseAdapter {
constructor(kumovegaResponse, instantsearchRequest) {
this.kumovegaResponse = kumovegaResponse;
this.instantsearchRequest = instantsearchRequest;
}
_adaptFacetHits(kumovegaFacetCounts) {
let adaptedResult = {};
const facet = kumovegaFacetCounts.find((facet) => facet.field_name === this.instantsearchRequest.params.facetName);
adaptedResult = facet.counts.map((facetCount) => ({
value: facetCount.value,
highlighted: this._adaptHighlightTag(
facetCount.highlighted,
this.instantsearchRequest.params.highlightPreTag,
this.instantsearchRequest.params.highlightPostTag,
),
count: facetCount.count,
}));
return adaptedResult;
}
adapt() {
const adaptedResult = {
facetHits: this._adaptFacetHits(this.kumovegaResponse.facet_counts),
exhaustiveFacetsCount: true,
processingTimeMS: this.kumovegaResponse.search_time_ms,
};
return adaptedResult;
}
}
Object.assign(FacetSearchResponseAdapter.prototype, utils);