-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
309f884
commit e98afe4
Showing
2 changed files
with
38 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...ins/enterprise_search/public/applications/app_search/components/relevance_tuning/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { cloneDeep } from 'lodash'; | ||
|
||
import { NUMBER } from '../../../shared/constants/field_types'; | ||
import { SchemaTypes } from '../../../shared/types'; | ||
|
||
import { SearchSettings } from './types'; | ||
|
||
// If the user hasn't entered a filter, then we can skip filtering the array entirely | ||
export const filterIfTerm = (array: string[], filterTerm: string): string[] => { | ||
return filterTerm === '' ? array : array.filter((item) => item.includes(filterTerm)); | ||
}; | ||
|
||
export const removeBoostStateProps = (searchSettings: SearchSettings) => { | ||
const updatedSettings = cloneDeep(searchSettings); | ||
const { boosts } = updatedSettings; | ||
const keys = Object.keys(boosts); | ||
keys.forEach((key) => boosts[key].forEach((boost) => delete boost.newBoost)); | ||
|
||
return updatedSettings; | ||
}; | ||
|
||
export const parseBoostCenter = (fieldType: SchemaTypes, value: string | number) => { | ||
// Leave non-numeric fields alone | ||
if (fieldType === NUMBER) { | ||
const floatValue = parseFloat(value as string); | ||
return isNaN(floatValue) ? value : floatValue; | ||
} | ||
return value; | ||
}; |