Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,11 @@ describe('RelevanceTuningLogic', () => {
weight: 1,
},
},
precision: 7,
precision_enabled: true,
};

const searchSettingsWithoutNewBoostProp = {
const { ['precision_enabled']: precisionEnabled, ...searchSettingsWithoutNewBoostProp } = {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check precision is being sent, but precision_enabled is not

...searchSettingsWithNewBoostProp,
boosts: {
foo: [
Expand All @@ -378,6 +380,7 @@ describe('RelevanceTuningLogic', () => {
},
],
},
precision: 7,
};

mount({
Expand Down Expand Up @@ -413,6 +416,38 @@ describe('RelevanceTuningLogic', () => {
searchSettings: {
searchField: {},
boosts: {},
precision: 7,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check precision being sent to search

precision_enabled: true,
},
});
jest.spyOn(RelevanceTuningLogic.actions, 'setSearchResults');
http.post.mockReturnValueOnce(
Promise.resolve({
results: searchResults,
})
);

RelevanceTuningLogic.actions.getSearchResults();

jest.runAllTimers();
await nextTick();

expect(http.post).toHaveBeenCalledWith('/internal/app_search/engines/test-engine/search', {
body: JSON.stringify({ precision: 7 }),
query: {
query: 'foo',
},
});
});

it("won't send precision on the API call if it is not enabled", async () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add test for precision not being sent

mount({
query: 'foo',
searchSettings: {
searchField: {},
boosts: {},
precision: 7,
precision_enabled: false,
},
});
jest.spyOn(RelevanceTuningLogic.actions, 'setSearchResults');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ export const RelevanceTuningLogic = kea<
actions.setResultsLoading(true);

const filteredBoosts = removeEmptyValueBoosts(boosts);
const precisionSettings = values.isPrecisionTuningEnabled ? { precision } : {};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actual fix (thanks @afoucret !): Do not send precision when precision tuning is not enabled


try {
const response = await http.post<{ results: SearchResult[] }>(url, {
Expand All @@ -303,7 +304,7 @@ export const RelevanceTuningLogic = kea<
body: JSON.stringify({
boosts: isEmpty(filteredBoosts) ? undefined : filteredBoosts,
search_fields: isEmpty(searchFields) ? undefined : searchFields,
precision,
...precisionSettings,
}),
});

Expand Down