|
7 | 7 |
|
8 | 8 | 'use strict' |
9 | 9 |
|
10 | | -import MeiliSearchTimeOutError from './errors/meilisearch-timeout-error' |
11 | 10 | import MeiliSearchError from './errors/meilisearch-error' |
| 11 | +import MeiliSearchTimeOutError from './errors/meilisearch-timeout-error' |
12 | 12 | import MeiliAxiosWrapper from './meili-axios-wrapper' |
13 | 13 | import * as Types from './types' |
14 | | -import { sleep, joinIfArray, createArrayIfString } from './utils' |
| 14 | +import { sleep } from './utils' |
15 | 15 |
|
16 | 16 | class Index<T> extends MeiliAxiosWrapper implements Types.IndexInterface<T> { |
17 | 17 | uid: string |
@@ -79,51 +79,44 @@ class Index<T> extends MeiliAxiosWrapper implements Types.IndexInterface<T> { |
79 | 79 | method: 'POST' | 'GET' = 'POST' |
80 | 80 | ): Promise<Types.SearchResponse<T, P>> { |
81 | 81 | const url = `/indexes/${this.uid}/search` |
82 | | - let params: Types.SearchRequest = { |
| 82 | + const params: Types.SearchRequest = { |
83 | 83 | q: query, |
84 | 84 | offset: options?.offset, |
85 | 85 | limit: options?.limit, |
86 | 86 | cropLength: options?.cropLength, |
87 | 87 | filters: options?.filters, |
88 | 88 | matches: options?.matches, |
| 89 | + facetFilters: options?.facetFilters, |
| 90 | + facetsDistribution: options?.facetsDistribution, |
| 91 | + attributesToRetrieve: options?.attributesToRetrieve, |
| 92 | + attributesToCrop: options?.attributesToCrop, |
| 93 | + attributesToHighlight: options?.attributesToHighlight, |
89 | 94 | } |
90 | 95 | if (method.toUpperCase() === 'POST') { |
91 | | - params = { |
92 | | - ...params, |
93 | | - facetFilters: options?.facetFilters, |
94 | | - facetsDistribution: options?.facetsDistribution, |
95 | | - attributesToRetrieve: options?.attributesToRetrieve |
96 | | - ? createArrayIfString(options.attributesToRetrieve) |
97 | | - : undefined, |
98 | | - attributesToCrop: options?.attributesToCrop |
99 | | - ? createArrayIfString(options.attributesToCrop) |
100 | | - : undefined, |
101 | | - attributesToHighlight: options?.attributesToHighlight |
102 | | - ? createArrayIfString(options.attributesToHighlight) |
103 | | - : undefined, |
104 | | - } |
105 | 96 | return await this.post(url, params, { |
106 | 97 | cancelToken: this.cancelTokenSource.token, |
107 | 98 | }) |
108 | 99 | } else if (method.toUpperCase() === 'GET') { |
109 | 100 | const getParams: Types.GetSearchRequest = { |
110 | 101 | ...params, |
111 | | - facetFilters: options?.facetFilters |
112 | | - ? JSON.stringify(options.facetFilters) |
113 | | - : undefined, |
| 102 | + facetFilters: |
| 103 | + Array.isArray(options?.facetFilters) && options?.facetFilters |
| 104 | + ? JSON.stringify(options.facetFilters) |
| 105 | + : undefined, |
114 | 106 | facetsDistribution: options?.facetsDistribution |
115 | 107 | ? JSON.stringify(options.facetsDistribution) |
116 | 108 | : undefined, |
117 | 109 | attributesToRetrieve: options?.attributesToRetrieve |
118 | | - ? joinIfArray(options.attributesToRetrieve) |
| 110 | + ? options.attributesToRetrieve.join(',') |
119 | 111 | : undefined, |
120 | 112 | attributesToCrop: options?.attributesToCrop |
121 | | - ? joinIfArray(options.attributesToCrop) |
| 113 | + ? options.attributesToCrop.join(',') |
122 | 114 | : undefined, |
123 | 115 | attributesToHighlight: options?.attributesToHighlight |
124 | | - ? joinIfArray(options.attributesToHighlight) |
| 116 | + ? options.attributesToHighlight.join(',') |
125 | 117 | : undefined, |
126 | 118 | } |
| 119 | + |
127 | 120 | return await this.get(url, { |
128 | 121 | params: getParams, |
129 | 122 | cancelToken: this.cancelTokenSource.token, |
|
0 commit comments