@@ -167,6 +167,61 @@ func (d *dbCatalogImpl) GetArtifacts(ctx context.Context, modelName string, sour
167167 return * artifactList , nil
168168}
169169
170+ func (d * dbCatalogImpl ) GetFilterOptions (ctx context.Context ) (* apimodels.FilterOptionsList , error ) {
171+ // Max length threshold for filter values (excludes verbose fields like readme, description)
172+ const maxFilterValueLength = 100
173+
174+ // Query database for filterable properties
175+ filterableProps , err := d .catalogModelRepository .GetFilterableProperties (maxFilterValueLength )
176+ if err != nil {
177+ return nil , err
178+ }
179+
180+ // Build FilterOptionsList
181+ options := make (map [string ]apimodels.FilterOption )
182+
183+ // Process each property and its values
184+ for fieldName , values := range filterableProps {
185+ // Skip internal/technical fields that shouldn't be exposed as filters
186+ if fieldName == "source_id" || fieldName == "logo" || fieldName == "license_link" {
187+ continue
188+ }
189+
190+ // Deduplicate values
191+ uniqueValues := make (map [string ]bool )
192+
193+ // Parse JSON arrays for fields like language and tasks
194+ for _ , value := range values {
195+ var arrayValues []string
196+ if err := json .Unmarshal ([]byte (value ), & arrayValues ); err == nil {
197+ // Successfully parsed as array, add individual values
198+ for _ , v := range arrayValues {
199+ uniqueValues [v ] = true
200+ }
201+ } else {
202+ // Not a JSON array
203+ uniqueValues [value ] = true
204+ }
205+ }
206+
207+ if len (uniqueValues ) > 0 {
208+ expandedValues := make ([]interface {}, 0 , len (uniqueValues ))
209+ for v := range uniqueValues {
210+ expandedValues = append (expandedValues , v )
211+ }
212+
213+ options [fieldName ] = apimodels.FilterOption {
214+ Type : "string" ,
215+ Values : expandedValues ,
216+ }
217+ }
218+ }
219+
220+ return & apimodels.FilterOptionsList {
221+ Filters : & options ,
222+ }, nil
223+ }
224+
170225func mapDBModelToAPIModel (m dbmodels.CatalogModel ) apimodels.CatalogModel {
171226 res := apimodels.CatalogModel {}
172227
0 commit comments