Skip to content

Commit

Permalink
[Enterprise Search] Do not include precision in the search request wh…
Browse files Browse the repository at this point in the history
…en precision tuning is not enabled for an Engine (elastic#136670)
  • Loading branch information
carlosdelest authored Jul 20, 2022
1 parent 2f732ae commit c43c827
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
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 } = {
...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,
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 () => {
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 } : {};

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

0 comments on commit c43c827

Please sign in to comment.