{"comment":{"url":"https://api.github.com/repos/liferay/com-liferay-adaptive-media/comments/19559008","html_url":"https://github.com/liferay/com-liferay-adaptive-media/commit/054dd98164ab69f11506a28bdb2d7f45341919d3#commitcomment-19559008","id":19559008,"user":{"login":"adolfopa","id":729897,"avatar_url":"https://avatars.githubusercontent.com/u/729897?v=3","gravatar_id":"","url":"https://api.github.com/users/adolfopa","html_url":"https://github.com/adolfopa","followers_url":"https://api.github.com/users/adolfopa/followers","following_url":"https://api.github.com/users/adolfopa/following{/other_user}","gists_url":"https://api.github.com/users/adolfopa/gists{/gist_id}","starred_url":"https://api.github.com/users/adolfopa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adolfopa/subscriptions","organizations_url":"https://api.github.com/users/adolfopa/orgs","repos_url":"https://api.github.com/users/adolfopa/repos","events_url":"https://api.github.com/users/adolfopa/events{/privacy}","received_events_url":"https://api.github.com/users/adolfopa/received_events","type":"User","site_admin":false},"position":27,"line":78,"path":"adaptive-media-api/src/main/java/com/liferay/adaptive/media/AdaptiveMediaAttribute.java","commit_id":"054dd98164ab69f11506a28bdb2d7f45341919d3","created_at":"2016-10-25T12:25:47Z","updated_at":"2016-10-25T12:25:47Z","body":"Hey @jhinkey ,\r\n\r\nAll media has a set of attributes (height, width, etc.). When someone asks for all the media associated with a resource, she may provide one or more property/value pairs in the query that represent what she really would like to get. For example:\r\n```\r\nfinder.getAdaptiveMedia(\r\n    queryBuilder ->\r\n        queryBuilder.forVersion(fileVersion)\r\n                            .with(HEIGHT, 100)\r\n                            .with(WIDTH, 200)\r\n                            .done();\r\n```\r\nThe thing is that there may be no media that exactly matches those requirements, but we must provide something anyway. So what we do is return a set of media that is ordered from best to worst fit.\r\n\r\nThe way we define this \"fitness\" is with the distance value. The distance is a non-negative integer that measures how far two values are from each other, and the particular definition/implementation depends on each attribute type. For example, in the case of the 'height' and 'width' attributes, the distance is what you would expect:\r\n```\r\ndistance(x, y) = |x - y|\r\n```\r\nFor data where the distance does not make a lot of sense, we define it as infinite (e.g. the 'content-type' attribute):\r\n```\r\ndistance(\"jpeg\", \"png\") = ∞\r\n```\r\nand so on.\r\n\r\nSo, in summary, the distance is the criteria used by the MediaFinder to sort the media, trying to return first the media that best matches the properties specified in the query.\r\n\r\nHope that helps."}}
{"actor":{"display_login":"adolfopa"}}