bzp2010 commented on code in PR #12291: URL: https://github.com/apache/apisix/pull/12291#discussion_r2135091189
########## apisix/admin/v3_adapter.lua: ########## @@ -120,11 +122,44 @@ local function pagination(body, args) end -local function filter(body, args) - if not args.name and not args.label and not args.uri then - return +local function _filter(item, args, resource) + if not args.filter then + return true + end + + local filters, err = ngx.decode_args(args.filter or "", 100) + if not filters then + log.error("failed to decode filter args: ", err) + return false + end + + for key, value in pairs(filters) do + if not resource.list_filter_fields[key] then + log.warn("filter field '", key, "' is not supported by resource: ", resource.name) + goto CONTINUE + end + + if not item[key] then + return false + end + + if type(value) == "table" then + value = value[#value] -- get the last value in the table + end + + local matched = re_find(item[key], value, "jo") Review Comment: In fact, it's hard to tell which fields need to be exact matches and which need to be fuzzy matches, and the current implementation is a duplication of previous filter parameters. I recognize that `name`, `uri` are not the same concept with exact ID in nature, but I don't have any good ideas at the moment for the following reasons. When the feature was written at the beginning, I expected it to be able to filter on any field inside any resource without more development work, so this fuzzy match was used. I later realized that how it could filter on any field, I would have a hard time dealing with fields that have complex nesting, such as upstream. so I finally decided to limit the scope to service_id and upstream_id on routes and stream routes. I didn't want to exclusively develop based on specific fields, but wanted to keep it generic. Right now the schema can't provide this additional information for this goal, so I have to resort to fuzzy matching. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org