forked from typesense/typesense-instantsearch-adapter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFacetSearchResponseAdapter.js
38 lines (31 loc) · 1.1 KB
/
FacetSearchResponseAdapter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"use strict";
import { utils } from "./support/utils";
export class FacetSearchResponseAdapter {
constructor(typesenseResponse, instantsearchRequest) {
this.typesenseResponse = typesenseResponse;
this.instantsearchRequest = instantsearchRequest;
}
_adaptFacetHits(typesenseFacetCounts) {
let adaptedResult = {};
const facet = typesenseFacetCounts.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.typesenseResponse.facet_counts),
exhaustiveFacetsCount: true,
processingTimeMS: this.typesenseResponse.search_time_ms,
};
return adaptedResult;
}
}
Object.assign(FacetSearchResponseAdapter.prototype, utils);