-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[App Search] Added relevance tuning search preview #93054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9ce7af9
Fix dem routes
JasonStoltz f822049
Added search results
JasonStoltz 3174a05
Added an 'enter a query' prompt
JasonStoltz ad0788d
Added a 'no results' prompt
JasonStoltz d468275
Lint fix
JasonStoltz d495903
Add schema highlights
JasonStoltz 4c9dfe6
Feedback from last PR
JasonStoltz 80eec74
Fix i18n
JasonStoltz 408984a
Removed duplicate spacer
JasonStoltz a268a79
Collapse preview
JasonStoltz 47b25b4
Use text searchPlaceholder for i18n
JasonStoltz eaf97ea
Use EmptyQueryPrompt for data attribute
JasonStoltz 1191f64
Merge branch 'master' into relevance-tuning-7
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
110 changes: 110 additions & 0 deletions
110
...lic/applications/app_search/components/relevance_tuning/relevance_tuning_preview.test.tsx
This file contains hidden or 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,110 @@ | ||
| /* | ||
| * 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 { setMockActions, setMockValues } from '../../../__mocks__/kea.mock'; | ||
|
|
||
| import React from 'react'; | ||
|
|
||
| import { shallow } from 'enzyme'; | ||
|
|
||
| import { EuiFieldSearch } from '@elastic/eui'; | ||
|
|
||
| import { Result } from '../result/result'; | ||
|
|
||
| import { RelevanceTuningPreview } from './relevance_tuning_preview'; | ||
|
|
||
| describe('RelevanceTuningPreview', () => { | ||
| const result1 = { id: { raw: 1 } }; | ||
| const result2 = { id: { raw: 2 } }; | ||
| const result3 = { id: { raw: 3 } }; | ||
|
|
||
| const actions = { | ||
| updateSearchValue: jest.fn(), | ||
| }; | ||
|
|
||
| const values = { | ||
| searchResults: [result1, result2, result3], | ||
| engineName: 'foo', | ||
| isMetaEngine: false, | ||
| schema: {}, | ||
| }; | ||
|
|
||
| beforeAll(() => { | ||
| setMockActions(actions); | ||
| setMockValues(values); | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('renders', () => { | ||
| const wrapper = shallow(<RelevanceTuningPreview />); | ||
|
|
||
| expect(wrapper.find(EuiFieldSearch).prop('placeholder')).toBe('Search foo'); | ||
|
|
||
| const results = wrapper.find(Result); | ||
| expect(results.length).toBe(3); | ||
| expect(results.at(0).prop('result')).toBe(result1); | ||
| expect(results.at(0).prop('isMetaEngine')).toBe(false); | ||
| expect(results.at(0).prop('showScore')).toBe(true); | ||
| expect(results.at(0).prop('schemaForTypeHighlights')).toBe(values.schema); | ||
|
|
||
| expect(results.at(1).prop('result')).toBe(result2); | ||
| expect(results.at(2).prop('result')).toBe(result3); | ||
|
|
||
| expect(wrapper.find('[data-test-subj="EmptyQueryPrompt"]').exists()).toBe(false); | ||
| expect(wrapper.find('[data-test-subj="NoResultsPrompt"]').exists()).toBe(false); | ||
| }); | ||
|
|
||
| it('correctly indicates whether or not this is a meta engine in results', () => { | ||
| setMockValues({ | ||
| ...values, | ||
| isMetaEngine: true, | ||
| }); | ||
|
|
||
| const wrapper = shallow(<RelevanceTuningPreview />); | ||
|
|
||
| const results = wrapper.find(Result); | ||
| expect(results.at(0).prop('isMetaEngine')).toBe(true); | ||
| expect(results.at(1).prop('isMetaEngine')).toBe(true); | ||
| expect(results.at(2).prop('isMetaEngine')).toBe(true); | ||
| }); | ||
|
|
||
| it('renders a search box that will update search results whenever it is changed', () => { | ||
| const wrapper = shallow(<RelevanceTuningPreview />); | ||
|
|
||
| wrapper.find(EuiFieldSearch).simulate('change', { target: { value: 'some search text' } }); | ||
|
|
||
| expect(actions.updateSearchValue).toHaveBeenCalledWith('some search text'); | ||
| }); | ||
|
|
||
| it('will show user a prompt to enter a query if they have not entered one', () => { | ||
| setMockValues({ | ||
| ...values, | ||
| // Since `searchResults` is initialized as undefined, an undefined value indicates | ||
| // that no query has been performed, which means they have no yet entered a query | ||
| searchResults: undefined, | ||
| }); | ||
|
|
||
| const wrapper = shallow(<RelevanceTuningPreview />); | ||
|
|
||
| expect(wrapper.find('[data-test-subj="EmptyQueryPrompt"]').exists()).toBe(true); | ||
| expect(wrapper.find('[data-test-subj="NoResultsPrompt"]').exists()).toBe(false); | ||
| }); | ||
|
|
||
| it('will show user a no results message if their query returns no results', () => { | ||
| setMockValues({ | ||
| ...values, | ||
| searchResults: [], | ||
| }); | ||
|
|
||
| const wrapper = shallow(<RelevanceTuningPreview />); | ||
|
|
||
| expect(wrapper.find('[data-test-subj="EmptyQueryPrompt"]').exists()).toBe(false); | ||
| expect(wrapper.find('[data-test-subj="NoResultsPrompt"]').exists()).toBe(true); | ||
| }); | ||
| }); |
91 changes: 91 additions & 0 deletions
91
...h/public/applications/app_search/components/relevance_tuning/relevance_tuning_preview.tsx
This file contains hidden or 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,91 @@ | ||
| /* | ||
| * 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 React from 'react'; | ||
|
|
||
| import { useActions, useValues } from 'kea'; | ||
|
|
||
| import { EuiEmptyPrompt, EuiFieldSearch, EuiPanel, EuiSpacer, EuiTitle } from '@elastic/eui'; | ||
|
|
||
| import { i18n } from '@kbn/i18n'; | ||
|
|
||
| import { EngineLogic } from '../engine'; | ||
| import { Result } from '../result/result'; | ||
|
|
||
| import { RelevanceTuningLogic } from '.'; | ||
|
|
||
| const emptyCallout = ( | ||
| <EuiEmptyPrompt | ||
| data-test-subj="EmptyQueryPrompt" | ||
| body={i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engine.relevanceTuning.preview.enterQueryMessage', | ||
| { | ||
| defaultMessage: 'Enter a query to see search results', | ||
| } | ||
| )} | ||
| /> | ||
| ); | ||
|
|
||
| const noResultsCallout = ( | ||
| <EuiEmptyPrompt | ||
| data-test-subj="NoResultsPrompt" | ||
| body={i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engine.relevanceTuning.preview.noResultsMessage', | ||
| { | ||
| defaultMessage: 'No matching content found', | ||
| } | ||
| )} | ||
| /> | ||
| ); | ||
|
|
||
| export const RelevanceTuningPreview: React.FC = () => { | ||
| const { updateSearchValue } = useActions(RelevanceTuningLogic); | ||
| const { searchResults, schema } = useValues(RelevanceTuningLogic); | ||
| const { engineName, isMetaEngine } = useValues(EngineLogic); | ||
|
|
||
| return ( | ||
| <EuiPanel> | ||
| <EuiTitle size="m"> | ||
| <h2> | ||
| {i18n.translate('xpack.enterpriseSearch.appSearch.engine.relevanceTuning.preview.title', { | ||
| defaultMessage: 'Preview', | ||
| })} | ||
| </h2> | ||
| </EuiTitle> | ||
| <EuiSpacer /> | ||
| <EuiFieldSearch | ||
| onChange={(e) => updateSearchValue(e.target.value)} | ||
| placeholder={i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engine.relevanceTuning.preview.searchPlaceholder', | ||
| { | ||
| defaultMessage: 'Search {engineName}', | ||
| values: { | ||
| engineName, | ||
| }, | ||
| } | ||
| )} | ||
| fullWidth | ||
| /> | ||
| {!searchResults && emptyCallout} | ||
| {searchResults && searchResults.length === 0 && noResultsCallout} | ||
| {searchResults && | ||
| searchResults.map((result) => { | ||
| return ( | ||
| <React.Fragment key={result.id.raw}> | ||
| <EuiSpacer size="m" /> | ||
| <Result | ||
| result={result} | ||
| showScore | ||
| isMetaEngine={isMetaEngine} | ||
| schemaForTypeHighlights={schema} | ||
| /> | ||
| </React.Fragment> | ||
| ); | ||
| })} | ||
cee-chen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </EuiPanel> | ||
| ); | ||
| }; | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.