[Enterprise Search] Do not include precision_enabled in requests for precision tuning (#137220) (#137563)

This commit is contained in:
Carlos Delgado 2022-07-29 13:26:42 +02:00 committed by GitHub
parent 867c736ddc
commit 3d0a7cacf0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 5 deletions

View file

@ -549,6 +549,8 @@ describe('RelevanceTuningLogic', () => {
},
],
},
precision: 5,
precision_enabled: true,
};
const searchSettingsWithoutNewBoostProp = {
@ -561,6 +563,7 @@ describe('RelevanceTuningLogic', () => {
},
],
},
precision: 5,
};
mount({
searchSettings: searchSettingsWithNewBoostProp,

View file

@ -65,10 +65,13 @@ export interface SearchField {
weight: number;
}
export interface SearchSettings {
export interface SearchSettingsRequest {
boosts: Record<string, Boost[]>;
search_fields: Record<string, SearchField>;
result_fields?: object;
precision: number;
}
export interface SearchSettings extends SearchSettingsRequest {
precision_enabled: boolean;
}

View file

@ -58,8 +58,10 @@ describe('removeBoostStateProps', () => {
precision: 10,
precision_enabled: true,
};
const { precision_enabled: precisionEnabled, ...searchSettingsWithoutPrecisionEnabled } =
searchSettings;
expect(removeBoostStateProps(searchSettings)).toEqual({
...searchSettings,
...searchSettingsWithoutPrecisionEnabled,
boosts: {
foo: [
{

View file

@ -9,15 +9,22 @@ import { cloneDeep, omit } from 'lodash';
import { SchemaType } from '../../../shared/schema/types';
import { RawBoost, Boost, SearchSettings, BoostType, ValueBoost } from './types';
import {
RawBoost,
Boost,
SearchSettingsRequest,
SearchSettings,
BoostType,
ValueBoost,
} 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): SearchSettings => {
const updatedSettings = cloneDeep(searchSettings);
export const removeBoostStateProps = (searchSettings: SearchSettings): SearchSettingsRequest => {
const { precision_enabled: precisionEnabled, ...updatedSettings } = cloneDeep(searchSettings);
const { boosts } = updatedSettings;
const keys = Object.keys(boosts);
keys.forEach((key) => boosts[key].forEach((boost) => delete boost.newBoost));