Skip to content

Commit 85a49a3

Browse files
committed
add get query set by id to router
Signed-off-by: Fen Qin <[email protected]>
1 parent d2b8810 commit 85a49a3

File tree

6 files changed

+161
-23
lines changed

6 files changed

+161
-23
lines changed

common/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ export const SEARCH_RELEVANCE_WORKBENCH = 'Search Relevance Workbench';
1212
* BACKEND SEARCH RELEVANCE APIs
1313
*/
1414
export const SEARCH_RELEVANCE_BASE_API = '/_plugins/search_relevance';
15-
export const SEARCH_RELEVANCE_QUERY_SET_API = `${SEARCH_RELEVANCE_BASE_API}/queryset`;
15+
export const SEARCH_RELEVANCE_QUERY_SET_API = `${SEARCH_RELEVANCE_BASE_API}/query_sets`;
16+
export const SEARCH_RELEVANCE_EXPERIMENT_API = `${SEARCH_RELEVANCE_BASE_API}/experiments`;
17+
export const SEARCH_RELEVANCE_JUDGMENT_API = `${SEARCH_RELEVANCE_BASE_API}/judgments`;
18+
export const SEARCH_RELEVANCE_SEARCH_CONFIGURATION = `${SEARCH_RELEVANCE_BASE_API}/search_configurations`;
1619

1720
/**
1821
* OPEN SEARCH CORE APIs
@@ -32,6 +35,11 @@ export const STATS_NODE_API_PATH = `${BASE_NODE_API_PATH}/stats`;
3235

3336
// Search Relevance node APIs
3437
export const BASE_QUERYSET_NODE_API_PATH = `${BASE_NODE_API_PATH}/queryset`;
38+
export const BASE_EXPERIMENT_NODE_API_PATH = `${BASE_NODE_API_PATH}/experiment`;
39+
export const BASE_JUDGMENT_NODE_API_PATH = `${BASE_NODE_API_PATH}/judgment`;
40+
export const BASE_SEARCH_CONFIG_NODE_API_PATH = `${BASE_NODE_API_PATH}/search_configuration`;
41+
42+
3543

3644
export const DEFAULT_HEADERS = {
3745
'Content-Type': 'application/json',

public/components/api/search_relevance_testing_page.tsx

Lines changed: 75 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,50 @@ import {
1515
EuiCallOut,
1616
EuiCodeBlock,
1717
} from '@elastic/eui';
18-
import { postQuerySet } from '../../services';
18+
import { postQuerySet, getQuerySets } from '../../services';
1919
import { CoreStart } from '../../../../../src/core/public';
2020

2121
export interface TestProps {
2222
http: CoreStart['http'];
2323
}
2424
export const QuerySetTester = ({ http }: TestProps) => {
25-
const [querySetId, setQuerySetId] = useState('');
26-
const [response, setResponse] = useState(null);
27-
const [isLoading, setIsLoading] = useState(false);
25+
const [name, setName] = useState('');
26+
const [description, setDescription] = useState('');
27+
const [createResponse, setCreateResponse] = useState(null);
28+
const [isCreateLoading, setIsCreateLoading] = useState(false);
29+
30+
const [id, setId] = useState('');
31+
const [getResponse, setGetResponse] = useState(null);
32+
const [isGetLoading, setIsGetLoading] = useState(false);
2833
const [error, setError] = useState(null);
2934

30-
const handleSubmit = async (e) => {
35+
const handleCreateSubmit = async (e) => {
3136
e.preventDefault();
32-
setIsLoading(true);
37+
setIsCreateLoading(true);
3338
setError(null);
3439

3540
try {
36-
const result = await postQuerySet(querySetId, http);
37-
setResponse(result);
41+
const postResult = await postQuerySet(name, description, http);
42+
setCreateResponse(postResult);
3843
} catch (err) {
3944
setError(err.message || 'An error occurred');
4045
} finally {
41-
setIsLoading(false);
46+
setIsCreateLoading(false);
47+
}
48+
};
49+
50+
const handleGetSubmit = async (e) => {
51+
e.preventDefault();
52+
setIsGetLoading(true);
53+
setError(null);
54+
55+
try {
56+
const listResult = await getQuerySets(id, http);
57+
setGetResponse(listResult);
58+
} catch (err) {
59+
setError(err.message || 'An error occurred');
60+
} finally {
61+
setIsGetLoading(false);
4262
}
4363
};
4464

@@ -48,19 +68,43 @@ export const QuerySetTester = ({ http }: TestProps) => {
4868
<h2>Query Set Tester</h2>
4969
</EuiText>
5070
<EuiSpacer size="m" />
51-
<EuiForm component="form" onSubmit={handleSubmit}>
52-
<EuiFormRow label="Query Set ID:">
71+
<EuiForm component="form" onSubmit={handleCreateSubmit}>
72+
<EuiFormRow label="Query Set Name:">
73+
<EuiFieldText
74+
placeholder="Enter Query Set Name"
75+
value={name}
76+
onChange={(e) => setName(e.target.value)}
77+
fullWidth
78+
/>
79+
</EuiFormRow>
80+
<EuiFormRow label="Query Set Description:">
5381
<EuiFieldText
54-
placeholder="Enter Query Set ID"
55-
value={querySetId}
56-
onChange={(e) => setQuerySetId(e.target.value)}
82+
placeholder="Enter Query Set Description"
83+
value={description}
84+
onChange={(e) => setDescription(e.target.value)}
5785
fullWidth
5886
/>
5987
</EuiFormRow>
6088
<EuiSpacer size="m" />
61-
<EuiButton type="submit" fill isLoading={isLoading}>
62-
{isLoading ? 'Sending...' : 'Send Request'}
89+
<EuiButton type="create submit" fill isCreateLoading={isCreateLoading}>
90+
{isCreateLoading ? 'Sending...' : 'Send Create Request'}
6391
</EuiButton>
92+
<EuiSpacer size="m" />
93+
</EuiForm>
94+
<EuiForm component="form" onSubmit={handleGetSubmit}>
95+
<EuiFormRow label="Get Query ID:">
96+
<EuiFieldText
97+
placeholder="Enter Get Query ID"
98+
value={id}
99+
onChange={(e) => setId(e.target.value)}
100+
fullWidth
101+
/>
102+
</EuiFormRow>
103+
<EuiSpacer size="m" />
104+
<EuiButton type="get submit" fill isGetLoading={isGetLoading}>
105+
{isCreateLoading ? 'Sending...' : 'Send Get Request'}
106+
</EuiButton>
107+
<EuiSpacer size="m" />
64108
</EuiForm>
65109
<EuiSpacer size="l" />
66110

@@ -70,14 +114,26 @@ export const QuerySetTester = ({ http }: TestProps) => {
70114
</EuiCallOut>
71115
)}
72116

73-
{response && (
117+
{createResponse && (
118+
<>
119+
<EuiText>
120+
<h3>Create Response:</h3>
121+
</EuiText>
122+
<EuiSpacer size="s" />
123+
<EuiCodeBlock language="json" paddingSize="m" isCopyable>
124+
{JSON.stringify(createResponse, null, 2)}
125+
</EuiCodeBlock>
126+
</>
127+
)}
128+
129+
{getResponse && (
74130
<>
75131
<EuiText>
76-
<h3>Response:</h3>
132+
<h3>Get Response:</h3>
77133
</EuiText>
78134
<EuiSpacer size="s" />
79135
<EuiCodeBlock language="json" paddingSize="m" isCopyable>
80-
{JSON.stringify(response, null, 2)}
136+
{typeof getResponse === 'string' ? getResponse : JSON.stringify(getResponse, null, 2)}
81137
</EuiCodeBlock>
82138
</>
83139
)}

public/components/app.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { PLUGIN_NAME, COMPARE_SEARCH_RESULTS_TITLE } from '../../common';
2424
import { SearchRelevanceContextProvider } from '../contexts';
2525
import { Home as QueryCompareHome } from './query_compare/home';
2626
import { ExperimentPage } from './experiment';
27+
import QuerySetTester from "./api/search_relevance_testing_page";
2728

2829
interface SearchRelevanceAppDeps {
2930
notifications: CoreStart['notifications'];
@@ -156,7 +157,7 @@ export const SearchRelevanceApp = ({
156157
setActionMenu={setActionMenu}
157158
/>
158159
) : (
159-
<ExperimentPage application={application} chrome={chrome} />
160+
<QuerySetTester http={http} />
160161
)}
161162
</>
162163
);

public/services.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,29 @@
55

66
import { BASE_QUERYSET_NODE_API_PATH } from '../common';
77

8-
export const postQuerySet = async (id: string, http: any) => {
8+
export const postQuerySet = async (name: string, description: string, http: any) => {
99
try {
1010
return await http.post(`..${BASE_QUERYSET_NODE_API_PATH}`, {
1111
body: JSON.stringify({
12-
querySetId: id,
12+
name,
13+
description,
1314
}),
1415
});
1516
} catch (e) {
1617
return e;
1718
}
1819
};
20+
21+
export const getQuerySets = async (id: string, http: any) => {
22+
try {
23+
const response = await http.get(`..${BASE_QUERYSET_NODE_API_PATH}/${id}`);
24+
// Add logging to debug
25+
// eslint-disable-next-line no-console
26+
console.log('GET Response:', response);
27+
return response;
28+
} catch (e) {
29+
// eslint-disable-next-line no-console
30+
console.error('GET Error:', e);
31+
return e;
32+
}
33+
};

server/clusters/search_relevance_plugin.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,17 @@ export default function searchRelevancePlugin(Client: any, config: any, componen
2121
},
2222
method: 'POST',
2323
});
24+
25+
searchRelevance.listQuerySets = ca({
26+
url: {
27+
fmt: `${SEARCH_RELEVANCE_QUERY_SET_API}/\${id}`,
28+
req: {
29+
id: {
30+
type: 'string',
31+
required: true,
32+
},
33+
},
34+
},
35+
method: 'GET',
36+
});
2437
}

server/routes/search_relevance_route_service.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ export function registerSearchRelevanceRoutes(
4949
},
5050
searchRelevanceRoutesService.createQuerySet
5151
);
52+
router.get(
53+
{
54+
path: `${BASE_QUERYSET_NODE_API_PATH}/{id}`,
55+
validate: {
56+
params: schema.object({
57+
id: schema.string(),
58+
}),
59+
},
60+
},
61+
searchRelevanceRoutesService.listQuerySets
62+
);
5263
}
5364

5465
export class SearchRelevanceRoutesService {
@@ -95,4 +106,38 @@ export class SearchRelevanceRoutesService {
95106
});
96107
}
97108
};
109+
110+
listQuerySets = async (
111+
context: RequestHandlerContext,
112+
req: OpenSearchDashboardsRequest,
113+
res: OpenSearchDashboardsResponseFactory
114+
): Promise<IOpenSearchDashboardsResponse<any>> => {
115+
const { id } = req.params;
116+
const { data_source_id = '' } = req.params as { data_source_id?: string };
117+
try {
118+
const callWithRequest = getClientBasedOnDataSource(
119+
context,
120+
this.dataSourceEnabled,
121+
req,
122+
data_source_id,
123+
this.client
124+
);
125+
126+
const querysetResponse = await callWithRequest('searchRelevance.listQuerySets', {
127+
id,
128+
});
129+
return res.ok({
130+
body: {
131+
ok: true,
132+
resp: querysetResponse,
133+
},
134+
});
135+
} catch (err) {
136+
return res.ok({
137+
body: {
138+
resp: err.message,
139+
},
140+
});
141+
}
142+
};
98143
}

0 commit comments

Comments
 (0)