From cd59cc7f120b08cec198438dd96d3bcba2d70d61 Mon Sep 17 00:00:00 2001 From: Anastasia Beglova Date: Wed, 9 Oct 2024 11:28:45 -0400 Subject: [PATCH] Content File Score Adjustment (#1667) --- frontends/api/src/generated/v1/api.ts | 82 ++++++++++ .../SearchDisplay/SearchDisplay.tsx | 21 +++ learning_resources_search/api.py | 19 ++- learning_resources_search/api_test.py | 146 ++++++++++-------- learning_resources_search/constants.py | 7 +- learning_resources_search/serializers.py | 10 ++ learning_resources_search/serializers_test.py | 2 + openapi/specs/v1.yaml | 48 ++++++ 8 files changed, 266 insertions(+), 69 deletions(-) diff --git a/frontends/api/src/generated/v1/api.ts b/frontends/api/src/generated/v1/api.ts index 0b518da320..fe52c1ee94 100644 --- a/frontends/api/src/generated/v1/api.ts +++ b/frontends/api/src/generated/v1/api.ts @@ -3862,6 +3862,12 @@ export interface PercolateQuerySubscriptionRequestRequest { * @memberof PercolateQuerySubscriptionRequestRequest */ max_incompleteness_penalty?: number | null + /** + * Score weight for content file data. 1 is the default. 0 means content files are ignored + * @type {number} + * @memberof PercolateQuerySubscriptionRequestRequest + */ + content_file_score_weight?: number | null /** * * @type {SourceTypeEnum} @@ -12873,6 +12879,7 @@ export const LearningResourcesSearchApiAxiosParamCreator = function ( * @param {Array} [aggregations] Show resource counts by category * @param {boolean | null} [certification] True if the learning resource offers a certificate * @param {Array} [certification_type] The type of certificate * `micromasters` - Micromasters Credential * `professional` - Professional Certificate * `completion` - Certificate of Completion * `none` - No Certificate + * @param {number | null} [content_file_score_weight] Score weight for content file data. 1 is the default. 0 means content files are ignored * @param {Array} [course_feature] The course feature. Possible options are at api/v1/course_features/ * @param {Array} [delivery] The delivery options in which the learning resource is offered * `online` - Online * `hybrid` - Hybrid * `in_person` - In person * `offline` - Offline * @param {Array} [department] The department that offers the learning resource * `1` - Civil and Environmental Engineering * `2` - Mechanical Engineering * `3` - Materials Science and Engineering * `4` - Architecture * `5` - Chemistry * `6` - Electrical Engineering and Computer Science * `7` - Biology * `8` - Physics * `9` - Brain and Cognitive Sciences * `10` - Chemical Engineering * `11` - Urban Studies and Planning * `12` - Earth, Atmospheric, and Planetary Sciences * `14` - Economics * `15` - Management * `16` - Aeronautics and Astronautics * `17` - Political Science * `18` - Mathematics * `20` - Biological Engineering * `21A` - Anthropology * `21G` - Global Languages * `21H` - History * `21L` - Literature * `21M` - Music and Theater Arts * `22` - Nuclear Science and Engineering * `24` - Linguistics and Philosophy * `CC` - Concourse * `CMS-W` - Comparative Media Studies/Writing * `EC` - Edgerton Center * `ES` - Experimental Study Group * `ESD` - Engineering Systems Division * `HST` - Medical Engineering and Science * `IDS` - Data, Systems, and Society * `MAS` - Media Arts and Sciences * `PE` - Athletics, Physical Education and Recreation * `SP` - Special Programs * `STS` - Science, Technology, and Society * `WGS` - Women\'s and Gender Studies @@ -12903,6 +12910,7 @@ export const LearningResourcesSearchApiAxiosParamCreator = function ( aggregations?: Array, certification?: boolean | null, certification_type?: Array, + content_file_score_weight?: number | null, course_feature?: Array, delivery?: Array, department?: Array, @@ -12956,6 +12964,11 @@ export const LearningResourcesSearchApiAxiosParamCreator = function ( localVarQueryParameter["certification_type"] = certification_type } + if (content_file_score_weight !== undefined) { + localVarQueryParameter["content_file_score_weight"] = + content_file_score_weight + } + if (course_feature) { localVarQueryParameter["course_feature"] = course_feature } @@ -13082,6 +13095,7 @@ export const LearningResourcesSearchApiFp = function ( * @param {Array} [aggregations] Show resource counts by category * @param {boolean | null} [certification] True if the learning resource offers a certificate * @param {Array} [certification_type] The type of certificate * `micromasters` - Micromasters Credential * `professional` - Professional Certificate * `completion` - Certificate of Completion * `none` - No Certificate + * @param {number | null} [content_file_score_weight] Score weight for content file data. 1 is the default. 0 means content files are ignored * @param {Array} [course_feature] The course feature. Possible options are at api/v1/course_features/ * @param {Array} [delivery] The delivery options in which the learning resource is offered * `online` - Online * `hybrid` - Hybrid * `in_person` - In person * `offline` - Offline * @param {Array} [department] The department that offers the learning resource * `1` - Civil and Environmental Engineering * `2` - Mechanical Engineering * `3` - Materials Science and Engineering * `4` - Architecture * `5` - Chemistry * `6` - Electrical Engineering and Computer Science * `7` - Biology * `8` - Physics * `9` - Brain and Cognitive Sciences * `10` - Chemical Engineering * `11` - Urban Studies and Planning * `12` - Earth, Atmospheric, and Planetary Sciences * `14` - Economics * `15` - Management * `16` - Aeronautics and Astronautics * `17` - Political Science * `18` - Mathematics * `20` - Biological Engineering * `21A` - Anthropology * `21G` - Global Languages * `21H` - History * `21L` - Literature * `21M` - Music and Theater Arts * `22` - Nuclear Science and Engineering * `24` - Linguistics and Philosophy * `CC` - Concourse * `CMS-W` - Comparative Media Studies/Writing * `EC` - Edgerton Center * `ES` - Experimental Study Group * `ESD` - Engineering Systems Division * `HST` - Medical Engineering and Science * `IDS` - Data, Systems, and Society * `MAS` - Media Arts and Sciences * `PE` - Athletics, Physical Education and Recreation * `SP` - Special Programs * `STS` - Science, Technology, and Society * `WGS` - Women\'s and Gender Studies @@ -13112,6 +13126,7 @@ export const LearningResourcesSearchApiFp = function ( aggregations?: Array, certification?: boolean | null, certification_type?: Array, + content_file_score_weight?: number | null, course_feature?: Array, delivery?: Array, department?: Array, @@ -13147,6 +13162,7 @@ export const LearningResourcesSearchApiFp = function ( aggregations, certification, certification_type, + content_file_score_weight, course_feature, delivery, department, @@ -13215,6 +13231,7 @@ export const LearningResourcesSearchApiFactory = function ( requestParameters.aggregations, requestParameters.certification, requestParameters.certification_type, + requestParameters.content_file_score_weight, requestParameters.course_feature, requestParameters.delivery, requestParameters.department, @@ -13272,6 +13289,13 @@ export interface LearningResourcesSearchApiLearningResourcesSearchRetrieveReques */ readonly certification_type?: Array + /** + * Score weight for content file data. 1 is the default. 0 means content files are ignored + * @type {number} + * @memberof LearningResourcesSearchApiLearningResourcesSearchRetrieve + */ + readonly content_file_score_weight?: number | null + /** * The course feature. Possible options are at api/v1/course_features/ * @type {Array} @@ -13458,6 +13482,7 @@ export class LearningResourcesSearchApi extends BaseAPI { requestParameters.aggregations, requestParameters.certification, requestParameters.certification_type, + requestParameters.content_file_score_weight, requestParameters.course_feature, requestParameters.delivery, requestParameters.department, @@ -13696,6 +13721,7 @@ export const LearningResourcesUserSubscriptionApiAxiosParamCreator = function ( * @param {Array} [aggregations] Show resource counts by category * @param {boolean | null} [certification] True if the learning resource offers a certificate * @param {Array} [certification_type] The type of certificate * `micromasters` - Micromasters Credential * `professional` - Professional Certificate * `completion` - Certificate of Completion * `none` - No Certificate + * @param {number | null} [content_file_score_weight] Score weight for content file data. 1 is the default. 0 means content files are ignored * @param {Array} [course_feature] The course feature. Possible options are at api/v1/course_features/ * @param {Array} [delivery] The delivery options in which the learning resource is offered * `online` - Online * `hybrid` - Hybrid * `in_person` - In person * `offline` - Offline * @param {Array} [department] The department that offers the learning resource * `1` - Civil and Environmental Engineering * `2` - Mechanical Engineering * `3` - Materials Science and Engineering * `4` - Architecture * `5` - Chemistry * `6` - Electrical Engineering and Computer Science * `7` - Biology * `8` - Physics * `9` - Brain and Cognitive Sciences * `10` - Chemical Engineering * `11` - Urban Studies and Planning * `12` - Earth, Atmospheric, and Planetary Sciences * `14` - Economics * `15` - Management * `16` - Aeronautics and Astronautics * `17` - Political Science * `18` - Mathematics * `20` - Biological Engineering * `21A` - Anthropology * `21G` - Global Languages * `21H` - History * `21L` - Literature * `21M` - Music and Theater Arts * `22` - Nuclear Science and Engineering * `24` - Linguistics and Philosophy * `CC` - Concourse * `CMS-W` - Comparative Media Studies/Writing * `EC` - Edgerton Center * `ES` - Experimental Study Group * `ESD` - Engineering Systems Division * `HST` - Medical Engineering and Science * `IDS` - Data, Systems, and Society * `MAS` - Media Arts and Sciences * `PE` - Athletics, Physical Education and Recreation * `SP` - Special Programs * `STS` - Science, Technology, and Society * `WGS` - Women\'s and Gender Studies @@ -13727,6 +13753,7 @@ export const LearningResourcesUserSubscriptionApiAxiosParamCreator = function ( aggregations?: Array, certification?: boolean | null, certification_type?: Array, + content_file_score_weight?: number | null, course_feature?: Array, delivery?: Array, department?: Array, @@ -13781,6 +13808,11 @@ export const LearningResourcesUserSubscriptionApiAxiosParamCreator = function ( localVarQueryParameter["certification_type"] = certification_type } + if (content_file_score_weight !== undefined) { + localVarQueryParameter["content_file_score_weight"] = + content_file_score_weight + } + if (course_feature) { localVarQueryParameter["course_feature"] = course_feature } @@ -13898,6 +13930,7 @@ export const LearningResourcesUserSubscriptionApiAxiosParamCreator = function ( * @param {Array} [aggregations] Show resource counts by category * @param {boolean | null} [certification] True if the learning resource offers a certificate * @param {Array} [certification_type] The type of certificate * `micromasters` - Micromasters Credential * `professional` - Professional Certificate * `completion` - Certificate of Completion * `none` - No Certificate + * @param {number | null} [content_file_score_weight] Score weight for content file data. 1 is the default. 0 means content files are ignored * @param {Array} [course_feature] The course feature. Possible options are at api/v1/course_features/ * @param {Array} [delivery] The delivery options in which the learning resource is offered * `online` - Online * `hybrid` - Hybrid * `in_person` - In person * `offline` - Offline * @param {Array} [department] The department that offers the learning resource * `1` - Civil and Environmental Engineering * `2` - Mechanical Engineering * `3` - Materials Science and Engineering * `4` - Architecture * `5` - Chemistry * `6` - Electrical Engineering and Computer Science * `7` - Biology * `8` - Physics * `9` - Brain and Cognitive Sciences * `10` - Chemical Engineering * `11` - Urban Studies and Planning * `12` - Earth, Atmospheric, and Planetary Sciences * `14` - Economics * `15` - Management * `16` - Aeronautics and Astronautics * `17` - Political Science * `18` - Mathematics * `20` - Biological Engineering * `21A` - Anthropology * `21G` - Global Languages * `21H` - History * `21L` - Literature * `21M` - Music and Theater Arts * `22` - Nuclear Science and Engineering * `24` - Linguistics and Philosophy * `CC` - Concourse * `CMS-W` - Comparative Media Studies/Writing * `EC` - Edgerton Center * `ES` - Experimental Study Group * `ESD` - Engineering Systems Division * `HST` - Medical Engineering and Science * `IDS` - Data, Systems, and Society * `MAS` - Media Arts and Sciences * `PE` - Athletics, Physical Education and Recreation * `SP` - Special Programs * `STS` - Science, Technology, and Society * `WGS` - Women\'s and Gender Studies @@ -13928,6 +13961,7 @@ export const LearningResourcesUserSubscriptionApiAxiosParamCreator = function ( aggregations?: Array, certification?: boolean | null, certification_type?: Array, + content_file_score_weight?: number | null, course_feature?: Array, delivery?: Array, department?: Array, @@ -13981,6 +14015,11 @@ export const LearningResourcesUserSubscriptionApiAxiosParamCreator = function ( localVarQueryParameter["certification_type"] = certification_type } + if (content_file_score_weight !== undefined) { + localVarQueryParameter["content_file_score_weight"] = + content_file_score_weight + } + if (course_feature) { localVarQueryParameter["course_feature"] = course_feature } @@ -14094,6 +14133,7 @@ export const LearningResourcesUserSubscriptionApiAxiosParamCreator = function ( * @param {Array} [aggregations] Show resource counts by category * @param {boolean | null} [certification] True if the learning resource offers a certificate * @param {Array} [certification_type] The type of certificate * `micromasters` - Micromasters Credential * `professional` - Professional Certificate * `completion` - Certificate of Completion * `none` - No Certificate + * @param {number | null} [content_file_score_weight] Score weight for content file data. 1 is the default. 0 means content files are ignored * @param {Array} [course_feature] The course feature. Possible options are at api/v1/course_features/ * @param {Array} [delivery] The delivery options in which the learning resource is offered * `online` - Online * `hybrid` - Hybrid * `in_person` - In person * `offline` - Offline * @param {Array} [department] The department that offers the learning resource * `1` - Civil and Environmental Engineering * `2` - Mechanical Engineering * `3` - Materials Science and Engineering * `4` - Architecture * `5` - Chemistry * `6` - Electrical Engineering and Computer Science * `7` - Biology * `8` - Physics * `9` - Brain and Cognitive Sciences * `10` - Chemical Engineering * `11` - Urban Studies and Planning * `12` - Earth, Atmospheric, and Planetary Sciences * `14` - Economics * `15` - Management * `16` - Aeronautics and Astronautics * `17` - Political Science * `18` - Mathematics * `20` - Biological Engineering * `21A` - Anthropology * `21G` - Global Languages * `21H` - History * `21L` - Literature * `21M` - Music and Theater Arts * `22` - Nuclear Science and Engineering * `24` - Linguistics and Philosophy * `CC` - Concourse * `CMS-W` - Comparative Media Studies/Writing * `EC` - Edgerton Center * `ES` - Experimental Study Group * `ESD` - Engineering Systems Division * `HST` - Medical Engineering and Science * `IDS` - Data, Systems, and Society * `MAS` - Media Arts and Sciences * `PE` - Athletics, Physical Education and Recreation * `SP` - Special Programs * `STS` - Science, Technology, and Society * `WGS` - Women\'s and Gender Studies @@ -14126,6 +14166,7 @@ export const LearningResourcesUserSubscriptionApiAxiosParamCreator = function ( aggregations?: Array, certification?: boolean | null, certification_type?: Array, + content_file_score_weight?: number | null, course_feature?: Array, delivery?: Array, department?: Array, @@ -14181,6 +14222,11 @@ export const LearningResourcesUserSubscriptionApiAxiosParamCreator = function ( localVarQueryParameter["certification_type"] = certification_type } + if (content_file_score_weight !== undefined) { + localVarQueryParameter["content_file_score_weight"] = + content_file_score_weight + } + if (course_feature) { localVarQueryParameter["course_feature"] = course_feature } @@ -14369,6 +14415,7 @@ export const LearningResourcesUserSubscriptionApiFp = function ( * @param {Array} [aggregations] Show resource counts by category * @param {boolean | null} [certification] True if the learning resource offers a certificate * @param {Array} [certification_type] The type of certificate * `micromasters` - Micromasters Credential * `professional` - Professional Certificate * `completion` - Certificate of Completion * `none` - No Certificate + * @param {number | null} [content_file_score_weight] Score weight for content file data. 1 is the default. 0 means content files are ignored * @param {Array} [course_feature] The course feature. Possible options are at api/v1/course_features/ * @param {Array} [delivery] The delivery options in which the learning resource is offered * `online` - Online * `hybrid` - Hybrid * `in_person` - In person * `offline` - Offline * @param {Array} [department] The department that offers the learning resource * `1` - Civil and Environmental Engineering * `2` - Mechanical Engineering * `3` - Materials Science and Engineering * `4` - Architecture * `5` - Chemistry * `6` - Electrical Engineering and Computer Science * `7` - Biology * `8` - Physics * `9` - Brain and Cognitive Sciences * `10` - Chemical Engineering * `11` - Urban Studies and Planning * `12` - Earth, Atmospheric, and Planetary Sciences * `14` - Economics * `15` - Management * `16` - Aeronautics and Astronautics * `17` - Political Science * `18` - Mathematics * `20` - Biological Engineering * `21A` - Anthropology * `21G` - Global Languages * `21H` - History * `21L` - Literature * `21M` - Music and Theater Arts * `22` - Nuclear Science and Engineering * `24` - Linguistics and Philosophy * `CC` - Concourse * `CMS-W` - Comparative Media Studies/Writing * `EC` - Edgerton Center * `ES` - Experimental Study Group * `ESD` - Engineering Systems Division * `HST` - Medical Engineering and Science * `IDS` - Data, Systems, and Society * `MAS` - Media Arts and Sciences * `PE` - Athletics, Physical Education and Recreation * `SP` - Special Programs * `STS` - Science, Technology, and Society * `WGS` - Women\'s and Gender Studies @@ -14400,6 +14447,7 @@ export const LearningResourcesUserSubscriptionApiFp = function ( aggregations?: Array, certification?: boolean | null, certification_type?: Array, + content_file_score_weight?: number | null, course_feature?: Array, delivery?: Array, department?: Array, @@ -14436,6 +14484,7 @@ export const LearningResourcesUserSubscriptionApiFp = function ( aggregations, certification, certification_type, + content_file_score_weight, course_feature, delivery, department, @@ -14481,6 +14530,7 @@ export const LearningResourcesUserSubscriptionApiFp = function ( * @param {Array} [aggregations] Show resource counts by category * @param {boolean | null} [certification] True if the learning resource offers a certificate * @param {Array} [certification_type] The type of certificate * `micromasters` - Micromasters Credential * `professional` - Professional Certificate * `completion` - Certificate of Completion * `none` - No Certificate + * @param {number | null} [content_file_score_weight] Score weight for content file data. 1 is the default. 0 means content files are ignored * @param {Array} [course_feature] The course feature. Possible options are at api/v1/course_features/ * @param {Array} [delivery] The delivery options in which the learning resource is offered * `online` - Online * `hybrid` - Hybrid * `in_person` - In person * `offline` - Offline * @param {Array} [department] The department that offers the learning resource * `1` - Civil and Environmental Engineering * `2` - Mechanical Engineering * `3` - Materials Science and Engineering * `4` - Architecture * `5` - Chemistry * `6` - Electrical Engineering and Computer Science * `7` - Biology * `8` - Physics * `9` - Brain and Cognitive Sciences * `10` - Chemical Engineering * `11` - Urban Studies and Planning * `12` - Earth, Atmospheric, and Planetary Sciences * `14` - Economics * `15` - Management * `16` - Aeronautics and Astronautics * `17` - Political Science * `18` - Mathematics * `20` - Biological Engineering * `21A` - Anthropology * `21G` - Global Languages * `21H` - History * `21L` - Literature * `21M` - Music and Theater Arts * `22` - Nuclear Science and Engineering * `24` - Linguistics and Philosophy * `CC` - Concourse * `CMS-W` - Comparative Media Studies/Writing * `EC` - Edgerton Center * `ES` - Experimental Study Group * `ESD` - Engineering Systems Division * `HST` - Medical Engineering and Science * `IDS` - Data, Systems, and Society * `MAS` - Media Arts and Sciences * `PE` - Athletics, Physical Education and Recreation * `SP` - Special Programs * `STS` - Science, Technology, and Society * `WGS` - Women\'s and Gender Studies @@ -14511,6 +14561,7 @@ export const LearningResourcesUserSubscriptionApiFp = function ( aggregations?: Array, certification?: boolean | null, certification_type?: Array, + content_file_score_weight?: number | null, course_feature?: Array, delivery?: Array, department?: Array, @@ -14546,6 +14597,7 @@ export const LearningResourcesUserSubscriptionApiFp = function ( aggregations, certification, certification_type, + content_file_score_weight, course_feature, delivery, department, @@ -14590,6 +14642,7 @@ export const LearningResourcesUserSubscriptionApiFp = function ( * @param {Array} [aggregations] Show resource counts by category * @param {boolean | null} [certification] True if the learning resource offers a certificate * @param {Array} [certification_type] The type of certificate * `micromasters` - Micromasters Credential * `professional` - Professional Certificate * `completion` - Certificate of Completion * `none` - No Certificate + * @param {number | null} [content_file_score_weight] Score weight for content file data. 1 is the default. 0 means content files are ignored * @param {Array} [course_feature] The course feature. Possible options are at api/v1/course_features/ * @param {Array} [delivery] The delivery options in which the learning resource is offered * `online` - Online * `hybrid` - Hybrid * `in_person` - In person * `offline` - Offline * @param {Array} [department] The department that offers the learning resource * `1` - Civil and Environmental Engineering * `2` - Mechanical Engineering * `3` - Materials Science and Engineering * `4` - Architecture * `5` - Chemistry * `6` - Electrical Engineering and Computer Science * `7` - Biology * `8` - Physics * `9` - Brain and Cognitive Sciences * `10` - Chemical Engineering * `11` - Urban Studies and Planning * `12` - Earth, Atmospheric, and Planetary Sciences * `14` - Economics * `15` - Management * `16` - Aeronautics and Astronautics * `17` - Political Science * `18` - Mathematics * `20` - Biological Engineering * `21A` - Anthropology * `21G` - Global Languages * `21H` - History * `21L` - Literature * `21M` - Music and Theater Arts * `22` - Nuclear Science and Engineering * `24` - Linguistics and Philosophy * `CC` - Concourse * `CMS-W` - Comparative Media Studies/Writing * `EC` - Edgerton Center * `ES` - Experimental Study Group * `ESD` - Engineering Systems Division * `HST` - Medical Engineering and Science * `IDS` - Data, Systems, and Society * `MAS` - Media Arts and Sciences * `PE` - Athletics, Physical Education and Recreation * `SP` - Special Programs * `STS` - Science, Technology, and Society * `WGS` - Women\'s and Gender Studies @@ -14622,6 +14675,7 @@ export const LearningResourcesUserSubscriptionApiFp = function ( aggregations?: Array, certification?: boolean | null, certification_type?: Array, + content_file_score_weight?: number | null, course_feature?: Array, delivery?: Array, department?: Array, @@ -14656,6 +14710,7 @@ export const LearningResourcesUserSubscriptionApiFp = function ( aggregations, certification, certification_type, + content_file_score_weight, course_feature, delivery, department, @@ -14757,6 +14812,7 @@ export const LearningResourcesUserSubscriptionApiFactory = function ( requestParameters.aggregations, requestParameters.certification, requestParameters.certification_type, + requestParameters.content_file_score_weight, requestParameters.course_feature, requestParameters.delivery, requestParameters.department, @@ -14801,6 +14857,7 @@ export const LearningResourcesUserSubscriptionApiFactory = function ( requestParameters.aggregations, requestParameters.certification, requestParameters.certification_type, + requestParameters.content_file_score_weight, requestParameters.course_feature, requestParameters.delivery, requestParameters.department, @@ -14844,6 +14901,7 @@ export const LearningResourcesUserSubscriptionApiFactory = function ( requestParameters.aggregations, requestParameters.certification, requestParameters.certification_type, + requestParameters.content_file_score_weight, requestParameters.course_feature, requestParameters.delivery, requestParameters.department, @@ -14921,6 +14979,13 @@ export interface LearningResourcesUserSubscriptionApiLearningResourcesUserSubscr */ readonly certification_type?: Array + /** + * Score weight for content file data. 1 is the default. 0 means content files are ignored + * @type {number} + * @memberof LearningResourcesUserSubscriptionApiLearningResourcesUserSubscriptionCheckList + */ + readonly content_file_score_weight?: number | null + /** * The course feature. Possible options are at api/v1/course_features/ * @type {Array} @@ -15117,6 +15182,13 @@ export interface LearningResourcesUserSubscriptionApiLearningResourcesUserSubscr */ readonly certification_type?: Array + /** + * Score weight for content file data. 1 is the default. 0 means content files are ignored + * @type {number} + * @memberof LearningResourcesUserSubscriptionApiLearningResourcesUserSubscriptionList + */ + readonly content_file_score_weight?: number | null + /** * The course feature. Possible options are at api/v1/course_features/ * @type {Array} @@ -15306,6 +15378,13 @@ export interface LearningResourcesUserSubscriptionApiLearningResourcesUserSubscr */ readonly certification_type?: Array + /** + * Score weight for content file data. 1 is the default. 0 means content files are ignored + * @type {number} + * @memberof LearningResourcesUserSubscriptionApiLearningResourcesUserSubscriptionSubscribeCreate + */ + readonly content_file_score_weight?: number | null + /** * The course feature. Possible options are at api/v1/course_features/ * @type {Array} @@ -15520,6 +15599,7 @@ export class LearningResourcesUserSubscriptionApi extends BaseAPI { requestParameters.aggregations, requestParameters.certification, requestParameters.certification_type, + requestParameters.content_file_score_weight, requestParameters.course_feature, requestParameters.delivery, requestParameters.department, @@ -15566,6 +15646,7 @@ export class LearningResourcesUserSubscriptionApi extends BaseAPI { requestParameters.aggregations, requestParameters.certification, requestParameters.certification_type, + requestParameters.content_file_score_weight, requestParameters.course_feature, requestParameters.delivery, requestParameters.department, @@ -15611,6 +15692,7 @@ export class LearningResourcesUserSubscriptionApi extends BaseAPI { requestParameters.aggregations, requestParameters.certification, requestParameters.certification_type, + requestParameters.content_file_score_weight, requestParameters.course_feature, requestParameters.delivery, requestParameters.department, diff --git a/frontends/mit-learn/src/page-components/SearchDisplay/SearchDisplay.tsx b/frontends/mit-learn/src/page-components/SearchDisplay/SearchDisplay.tsx index 704261b0b8..1b021312c6 100644 --- a/frontends/mit-learn/src/page-components/SearchDisplay/SearchDisplay.tsx +++ b/frontends/mit-learn/src/page-components/SearchDisplay/SearchDisplay.tsx @@ -562,6 +562,7 @@ const SearchDisplay: React.FC = ({ max_incompleteness_penalty: searchParams.get( "max_incompleteness_penalty", ), + content_file_score_weight: searchParams.get("content_file_score_weight"), ...requestParams, aggregations: (facetNames || []).concat([ "resource_category", @@ -739,6 +740,26 @@ const SearchDisplay: React.FC = ({ the degree of incompleteness. Only affects results if there is a search term. + + Content File Score Weight Adjustment + + + + Score weight adjustment for content file matches. 1 means no + adjustment. 0 means content file matches are not counted in the + score. Only affects the results if there is a search term. + ) : null} diff --git a/learning_resources_search/api.py b/learning_resources_search/api.py index b529fb8b88..618e731eeb 100644 --- a/learning_resources_search/api.py +++ b/learning_resources_search/api.py @@ -199,7 +199,9 @@ def generate_content_file_text_clause(text): return wrap_text_clause(text_query) -def generate_learning_resources_text_clause(text, search_mode, slop): +def generate_learning_resources_text_clause( + text, search_mode, slop, content_file_score_weight +): """ Return text clause for the query @@ -221,6 +223,14 @@ def generate_learning_resources_text_clause(text, search_mode, slop): if search_mode == "phrase" and slop: extra_params["slop"] = slop + if content_file_score_weight is not None: + resourcefile_fields = [ + f"{field}^{content_file_score_weight}" + for field in RESOURCEFILE_QUERY_FIELDS + ] + else: + resourcefile_fields = RESOURCEFILE_QUERY_FIELDS + if text: text_query = { "should": [ @@ -302,7 +312,7 @@ def generate_learning_resources_text_clause(text, search_mode, slop): "query": { query_type: { "query": text, - "fields": RESOURCEFILE_QUERY_FIELDS, + "fields": resourcefile_fields, **extra_params, } }, @@ -557,7 +567,10 @@ def add_text_query_to_search(search, text, search_params, query_type_query): text_query = generate_content_file_text_clause(text) else: text_query = generate_learning_resources_text_clause( - text, search_params.get("search_mode"), search_params.get("slop") + text, + search_params.get("search_mode"), + search_params.get("slop"), + search_params.get("content_file_score_weight"), ) yearly_decay_percent = search_params.get("yearly_decay_percent") diff --git a/learning_resources_search/api_test.py b/learning_resources_search/api_test.py index c8d90a4cc3..068e89595b 100644 --- a/learning_resources_search/api_test.py +++ b/learning_resources_search/api_test.py @@ -135,7 +135,10 @@ def test_generate_sort_clause(sort_param, departments, result): @pytest.mark.parametrize("search_mode", ["best_fields", "most_fields", "phrase", None]) @pytest.mark.parametrize("slop", [None, 2]) -def test_generate_learning_resources_text_clause(search_mode, slop): +@pytest.mark.parametrize("content_file_score_weight", [None, 0, 0.5, 1]) +def test_generate_learning_resources_text_clause( + search_mode, slop, content_file_score_weight +): extra_params = {} if search_mode: @@ -144,6 +147,23 @@ def test_generate_learning_resources_text_clause(search_mode, slop): if search_mode == "phrase" and slop: extra_params["slop"] = slop + if content_file_score_weight is None: + content_file_fields = [ + "content.english", + "title.english", + "content_title.english", + "description.english", + "content_feature_type", + ] + else: + content_file_fields = [ + f"content.english^{content_file_score_weight}", + f"title.english^{content_file_score_weight}", + f"content_title.english^{content_file_score_weight}", + f"description.english^{content_file_score_weight}", + f"content_feature_type^{content_file_score_weight}", + ] + result1 = { "bool": { "filter": { @@ -251,12 +271,7 @@ def test_generate_learning_resources_text_clause(search_mode, slop): "query": { "multi_match": { "query": "math", - "fields": [ - "content", - "title.english^3", - "short_description.english^2", - "content_feature_type", - ], + "fields": content_file_fields, **extra_params, } }, @@ -365,12 +380,7 @@ def test_generate_learning_resources_text_clause(search_mode, slop): "query": { "multi_match": { "query": "math", - "fields": [ - "content", - "title.english^3", - "short_description.english^2", - "content_feature_type", - ], + "fields": content_file_fields, **extra_params, } }, @@ -482,12 +492,7 @@ def test_generate_learning_resources_text_clause(search_mode, slop): "query": { "query_string": { "query": '"math"', - "fields": [ - "content", - "title.english^3", - "short_description.english^2", - "content_feature_type", - ], + "fields": content_file_fields, } }, "score_mode": "avg", @@ -590,12 +595,7 @@ def test_generate_learning_resources_text_clause(search_mode, slop): "query": { "query_string": { "query": '"math"', - "fields": [ - "content", - "title.english^3", - "short_description.english^2", - "content_feature_type", - ], + "fields": content_file_fields, } }, "score_mode": "avg", @@ -604,9 +604,17 @@ def test_generate_learning_resources_text_clause(search_mode, slop): ], } } - assert generate_learning_resources_text_clause("math", search_mode, slop) == result1 assert ( - generate_learning_resources_text_clause('"math"', search_mode, slop) == result2 + generate_learning_resources_text_clause( + "math", search_mode, slop, content_file_score_weight + ) + == result1 + ) + assert ( + generate_learning_resources_text_clause( + '"math"', search_mode, slop, content_file_score_weight + ) + == result2 ) @@ -623,9 +631,10 @@ def test_generate_content_file_text_clause(): "multi_match": { "query": "math", "fields": [ - "content", - "title.english^3", - "short_description.english^2", + "content.english", + "title.english", + "content_title.english", + "description.english", "content_feature_type", ], } @@ -655,9 +664,10 @@ def test_generate_content_file_text_clause(): "multi_match": { "query": "math", "fields": [ - "content", - "title.english^3", - "short_description.english^2", + "content.english", + "title.english", + "content_title.english", + "description.english", "content_feature_type", ], } @@ -691,9 +701,10 @@ def test_generate_content_file_text_clause(): "query_string": { "query": '"math"', "fields": [ - "content", - "title.english^3", - "short_description.english^2", + "content.english", + "title.english", + "content_title.english", + "description.english", "content_feature_type", ], } @@ -723,9 +734,10 @@ def test_generate_content_file_text_clause(): "query_string": { "query": '"math"', "fields": [ - "content", - "title.english^3", - "short_description.english^2", + "content.english", + "title.english", + "content_title.english", + "description.english", "content_feature_type", ], } @@ -1170,9 +1182,10 @@ def test_execute_learn_search_for_learning_resource_query(opensearch): "multi_match": { "query": "math", "fields": [ - "content", - "title.english^3", - "short_description.english^2", + "content.english", + "title.english", + "content_title.english", + "description.english", "content_feature_type", ], "type": "best_fields", @@ -1289,9 +1302,10 @@ def test_execute_learn_search_for_learning_resource_query(opensearch): "multi_match": { "query": "math", "fields": [ - "content", - "title.english^3", - "short_description.english^2", + "content.english", + "title.english", + "content_title.english", + "description.english", "content_feature_type", ], "type": "best_fields", @@ -1639,9 +1653,10 @@ def test_execute_learn_search_with_script_score( "multi_match": { "query": "math", "fields": [ - "content", - "title.english^3", - "short_description.english^2", + "content.english", + "title.english", + "content_title.english", + "description.english", "content_feature_type", ], "type": "phrase", @@ -1758,9 +1773,10 @@ def test_execute_learn_search_with_script_score( "multi_match": { "query": "math", "fields": [ - "content", - "title.english^3", - "short_description.english^2", + "content.english", + "title.english", + "content_title.english", + "description.english", "content_feature_type", ], "type": "phrase", @@ -2068,9 +2084,10 @@ def test_execute_learn_search_with_min_score(mocker, settings, opensearch): "multi_match": { "query": "math", "fields": [ - "content", - "title.english^3", - "short_description.english^2", + "content.english", + "title.english", + "content_title.english", + "description.english", "content_feature_type", ], "type": "best_fields", @@ -2187,9 +2204,10 @@ def test_execute_learn_search_with_min_score(mocker, settings, opensearch): "multi_match": { "query": "math", "fields": [ - "content", - "title.english^3", - "short_description.english^2", + "content.english", + "title.english", + "content_title.english", + "description.english", "content_feature_type", ], "type": "best_fields", @@ -2388,9 +2406,10 @@ def test_execute_learn_search_for_content_file_query(opensearch): "multi_match": { "query": "math", "fields": [ - "content", - "title.english^3", - "short_description.english^2", + "content.english", + "title.english", + "content_title.english", + "description.english", "content_feature_type", ], } @@ -2421,9 +2440,10 @@ def test_execute_learn_search_for_content_file_query(opensearch): "multi_match": { "query": "math", "fields": [ - "content", - "title.english^3", - "short_description.english^2", + "content.english", + "title.english", + "content_title.english", + "description.english", "content_feature_type", ], } diff --git a/learning_resources_search/constants.py b/learning_resources_search/constants.py index d64ac12ada..6cf1ad993c 100644 --- a/learning_resources_search/constants.py +++ b/learning_resources_search/constants.py @@ -387,9 +387,10 @@ class FilterConfig: ] RESOURCEFILE_QUERY_FIELDS = [ - "content", - "title.english^3", - "short_description.english^2", + "content.english", + "title.english", + "content_title.english", + "description.english", "content_feature_type", ] diff --git a/learning_resources_search/serializers.py b/learning_resources_search/serializers.py index 2addd6fa4d..95186b0a6c 100644 --- a/learning_resources_search/serializers.py +++ b/learning_resources_search/serializers.py @@ -456,6 +456,16 @@ class LearningResourcesSearchRequestSerializer(SearchRequestSerializer): "search term." ), ) + content_file_score_weight = serializers.FloatField( + max_value=1, + min_value=0, + required=False, + allow_null=True, + help_text=( + "Score weight for content file data. 1 is the default." + " 0 means content files are ignored" + ), + ) class ContentFileSearchRequestSerializer(SearchRequestSerializer): diff --git a/learning_resources_search/serializers_test.py b/learning_resources_search/serializers_test.py index 43d97c6154..93721381d7 100644 --- a/learning_resources_search/serializers_test.py +++ b/learning_resources_search/serializers_test.py @@ -929,6 +929,7 @@ def test_learning_resources_search_request_serializer(): "slop": 2, "min_score": 0, "max_incompleteness_penalty": 25, + "content_file_score_weight": 0, } cleaned = { @@ -955,6 +956,7 @@ def test_learning_resources_search_request_serializer(): "slop": 2, "min_score": 0, "max_incompleteness_penalty": 25, + "content_file_score_weight": 0, } serialized = LearningResourcesSearchRequestSerializer(data=data) diff --git a/openapi/specs/v1.yaml b/openapi/specs/v1.yaml index e0a8571a55..50613b77cd 100644 --- a/openapi/specs/v1.yaml +++ b/openapi/specs/v1.yaml @@ -2320,6 +2320,16 @@ paths: description: "The type of certificate \n\n* `micromasters` - Micromasters\ \ Credential\n* `professional` - Professional Certificate\n* `completion`\ \ - Certificate of Completion\n* `none` - No Certificate" + - in: query + name: content_file_score_weight + schema: + type: number + format: double + maximum: 1 + minimum: 0 + nullable: true + description: Score weight for content file data. 1 is the default. 0 means + content files are ignored - in: query name: course_feature schema: @@ -2808,6 +2818,16 @@ paths: description: "The type of certificate \n\n* `micromasters` - Micromasters\ \ Credential\n* `professional` - Professional Certificate\n* `completion`\ \ - Certificate of Completion\n* `none` - No Certificate" + - in: query + name: content_file_score_weight + schema: + type: number + format: double + maximum: 1 + minimum: 0 + nullable: true + description: Score weight for content file data. 1 is the default. 0 means + content files are ignored - in: query name: course_feature schema: @@ -3321,6 +3341,16 @@ paths: description: "The type of certificate \n\n* `micromasters` - Micromasters\ \ Credential\n* `professional` - Professional Certificate\n* `completion`\ \ - Certificate of Completion\n* `none` - No Certificate" + - in: query + name: content_file_score_weight + schema: + type: number + format: double + maximum: 1 + minimum: 0 + nullable: true + description: Score weight for content file data. 1 is the default. 0 means + content files are ignored - in: query name: course_feature schema: @@ -3825,6 +3855,16 @@ paths: description: "The type of certificate \n\n* `micromasters` - Micromasters\ \ Credential\n* `professional` - Professional Certificate\n* `completion`\ \ - Certificate of Completion\n* `none` - No Certificate" + - in: query + name: content_file_score_weight + schema: + type: number + format: double + maximum: 1 + minimum: 0 + nullable: true + description: Score weight for content file data. 1 is the default. 0 means + content files are ignored - in: query name: course_feature schema: @@ -10340,6 +10380,14 @@ components: An OCW course with completeness = 0 will have this score penalty. Partially complete courses have a linear penalty proportional to the degree of incompleteness. Only affects results if there is a search term. + content_file_score_weight: + type: number + format: double + maximum: 1 + minimum: 0 + nullable: true + description: Score weight for content file data. 1 is the default. 0 means + content files are ignored source_type: allOf: - $ref: '#/components/schemas/SourceTypeEnum'