@@ -58,62 +58,62 @@ class Index<T> implements Types.IndexInterface<T> {
5858 async search < P extends Types . SearchParams < T > > (
5959 query ?: string | null ,
6060 options ?: P ,
61- method : Types . Methods = 'POST' ,
6261 config ?: Partial < Request >
6362 ) : Promise < Types . SearchResponse < T , P > > {
6463 const url = `indexes/${ this . uid } /search`
65- const params : Types . SearchRequest = {
66- q : query ,
67- offset : options ?. offset ,
68- limit : options ?. limit ,
69- cropLength : options ?. cropLength ,
70- filter : options ?. filter ,
71- matches : options ?. matches ,
72- facetsDistribution : options ?. facetsDistribution ,
73- attributesToRetrieve : options ?. attributesToRetrieve ,
74- attributesToCrop : options ?. attributesToCrop ,
75- attributesToHighlight : options ?. attributesToHighlight ,
64+
65+ return await this . httpRequest . post (
66+ url ,
67+ removeUndefinedFromObject ( { ...options , q : query } ) ,
68+ undefined ,
69+ config
70+ )
71+ }
72+
73+ /**
74+ * Search for documents into an index using the GET method
75+ * @memberof Index
76+ * @method search
77+ */
78+ async searchGet < P extends Types . SearchParams < T > > (
79+ query ?: string | null ,
80+ options ?: P ,
81+ config ?: Partial < Request >
82+ ) : Promise < Types . SearchResponse < T , P > > {
83+ const url = `indexes/${ this . uid } /search`
84+
85+ const parseFilter = ( filter ?: Types . Filter ) : string | undefined => {
86+ if ( typeof filter === 'string' ) return filter
87+ else if ( Array . isArray ( filter ) )
88+ throw new MeiliSearchError (
89+ 'The filter query parameter should be in string format when using searchGet'
90+ )
91+ else return undefined
7692 }
77- if ( method . toUpperCase ( ) === 'POST' ) {
78- return await this . httpRequest . post (
79- url ,
80- removeUndefinedFromObject ( params ) ,
81- undefined ,
82- config
83- )
84- } else if ( method . toUpperCase ( ) === 'GET' ) {
85- const parseFilter = ( filter ?: any ) => {
86- if ( typeof filter === 'string' ) return filter
87- else if ( Array . isArray ( filter ) ) return JSON . stringify ( filter )
88- else return undefined
89- }
90- const getParams : Types . GetSearchRequest = {
91- ...params ,
92- filter : parseFilter ( options ?. filter ) ,
93- facetsDistribution : options ?. facetsDistribution
94- ? JSON . stringify ( options . facetsDistribution )
95- : undefined ,
96- attributesToRetrieve : options ?. attributesToRetrieve
97- ? options . attributesToRetrieve . join ( ',' )
98- : undefined ,
99- attributesToCrop : options ?. attributesToCrop
100- ? options . attributesToCrop . join ( ',' )
101- : undefined ,
102- attributesToHighlight : options ?. attributesToHighlight
103- ? options . attributesToHighlight . join ( ',' )
104- : undefined ,
105- }
10693
107- return await this . httpRequest . get < Types . SearchResponse < T , P > > (
108- url ,
109- removeUndefinedFromObject ( getParams ) ,
110- config
111- )
112- } else {
113- throw new MeiliSearchError (
114- 'method parameter should be either POST or GET'
115- )
94+ const getParams : Types . SearchRequestGET = {
95+ q : query ,
96+ ...options ,
97+ filter : parseFilter ( options ?. filter ) ,
98+ facetsDistribution : options ?. facetsDistribution
99+ ? options . facetsDistribution . join ( ',' )
100+ : undefined ,
101+ attributesToRetrieve : options ?. attributesToRetrieve
102+ ? options . attributesToRetrieve . join ( ',' )
103+ : undefined ,
104+ attributesToCrop : options ?. attributesToCrop
105+ ? options . attributesToCrop . join ( ',' )
106+ : undefined ,
107+ attributesToHighlight : options ?. attributesToHighlight
108+ ? options . attributesToHighlight . join ( ',' )
109+ : undefined ,
116110 }
111+
112+ return await this . httpRequest . get < Types . SearchResponse < T , P > > (
113+ url ,
114+ removeUndefinedFromObject ( getParams ) ,
115+ config
116+ )
117117 }
118118
119119 ///
0 commit comments