UNPKG

2.21 kBJavaScriptView Raw
1"use strict";
2/* eslint jsdoc/require-jsdoc: off */
3Object.defineProperty(exports, "__esModule", { value: true });
4exports.DateSearchFacet = exports.NumericSearchFacet = exports.TermSearchFacet = exports.SearchFacet = void 0;
5/**
6 * Provides the ability to specify facets for a search query.
7 *
8 * @category Full Text Search
9 */
10class SearchFacet {
11 constructor(data) {
12 if (!data) {
13 data = {};
14 }
15 this._data = data;
16 }
17 toJSON() {
18 return this._data;
19 }
20 static term(field, size) {
21 return new TermSearchFacet(field, size);
22 }
23 static numeric(field, size) {
24 return new NumericSearchFacet(field, size);
25 }
26 static date(field, size) {
27 return new DateSearchFacet(field, size);
28 }
29}
30exports.SearchFacet = SearchFacet;
31/**
32 * Provides ability to request a term facet.
33 *
34 * @category Full Text Search
35 */
36class TermSearchFacet extends SearchFacet {
37 /**
38 * @internal
39 */
40 constructor(field, size) {
41 super({
42 field: field,
43 size: size,
44 });
45 }
46}
47exports.TermSearchFacet = TermSearchFacet;
48/**
49 * Provides ability to request a numeric facet.
50 *
51 * @category Full Text Search
52 */
53class NumericSearchFacet extends SearchFacet {
54 /**
55 * @internal
56 */
57 constructor(field, size) {
58 super({
59 field: field,
60 size: size,
61 numeric_ranges: [],
62 });
63 }
64 addRange(name, min, max) {
65 this._data.numeric_ranges.push({
66 name: name,
67 min: min,
68 max: max,
69 });
70 return this;
71 }
72}
73exports.NumericSearchFacet = NumericSearchFacet;
74/**
75 * Provides ability to request a date facet.
76 *
77 * @category Full Text Search
78 */
79class DateSearchFacet extends SearchFacet {
80 /**
81 * @internal
82 */
83 constructor(field, size) {
84 super({
85 field: field,
86 size: size,
87 date_ranges: [],
88 });
89 }
90 addRange(name, start, end) {
91 this._data.date_ranges.push({
92 name: name,
93 start: start,
94 end: end,
95 });
96 return this;
97 }
98}
99exports.DateSearchFacet = DateSearchFacet;