@@ -120,21 +120,21 @@ func ParseQueries(queries []storage.Query) ([]interface{}, error) {
120120 return filter , nil
121121}
122122
123- // ConvertToFilter 将 map 转换为 Meilisearch 等值过滤器
124- // 输入示例 :
123+ // ConvertToFilter convert the map to a meilisearch equivalent filter
124+ // Input :
125125//
126126// {
127127// "category": "electronics",
128128// "tags": ["a", "b"],
129129// "author": {"name": "Alice"}
130130// }
131131//
132- // 输出 : ["category = 'electronics'", "tags IN ['a','b']", "author.name = 'Alice'"]
132+ // Output : ["category = 'electronics'", "tags IN ['a','b']", "author.name = 'Alice'"]
133133func ConvertToFilter (query map [string ]any ) ([]any , error ) {
134134 return processMap (query , "" )
135135}
136136
137- // 递归处理嵌套 map
137+ // recursively handles nesting map
138138func processMap (data map [string ]any , parentKey string ) ([]any , error ) {
139139 var filters []any
140140
@@ -146,23 +146,20 @@ func processMap(data map[string]any, parentKey string) ([]any, error) {
146146
147147 switch v := value .(type ) {
148148 case map [string ]any :
149- // 处理嵌套对象
150149 nestedFilters , err := processMap (v , fullKey )
151150 if err != nil {
152151 return nil , err
153152 }
154153 filters = append (filters , nestedFilters )
155154
156155 case []any :
157- // 处理数组 (IN 查询)
158156 inClause , err := buildInClause (fullKey , v )
159157 if err != nil {
160158 return nil , err
161159 }
162160 filters = append (filters , inClause )
163161
164162 default :
165- // 处理基本类型
166163 eqClause , err := buildEqualClause (fullKey , v )
167164 if err != nil {
168165 return nil , err
@@ -174,7 +171,7 @@ func processMap(data map[string]any, parentKey string) ([]any, error) {
174171 return filters , nil
175172}
176173
177- // 构建等值条件
174+ // build an equivalence condition
178175func buildEqualClause (key string , value any ) (string , error ) {
179176 valueStr , err := convertValue (value )
180177 if err != nil {
@@ -183,7 +180,7 @@ func buildEqualClause(key string, value any) (string, error) {
183180 return fmt .Sprintf ("%s = %s" , key , valueStr ), nil
184181}
185182
186- // 构建 IN 条件
183+ // build an in condition
187184func buildInClause (key string , values []any ) (string , error ) {
188185 var elements []string
189186 for _ , v := range values {
@@ -196,7 +193,7 @@ func buildInClause(key string, values []any) (string, error) {
196193 return fmt .Sprintf ("%s IN [%s]" , key , strings .Join (elements , "," )), nil
197194}
198195
199- // 值类型转换
196+ // value type conversion
200197func convertValue (value any ) (string , error ) {
201198 switch v := value .(type ) {
202199 case string :
0 commit comments