Skip to content

add put/get/list/delete operations for query_set, search_configuration and experiment APIs #495

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 9 additions & 1 deletion common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export const SEARCH_RELEVANCE_WORKBENCH = 'Search Relevance Workbench';
* BACKEND SEARCH RELEVANCE APIs
*/
export const SEARCH_RELEVANCE_BASE_API = '/_plugins/search_relevance';
export const SEARCH_RELEVANCE_QUERY_SET_API = `${SEARCH_RELEVANCE_BASE_API}/queryset`;
export const SEARCH_RELEVANCE_QUERY_SET_API = `${SEARCH_RELEVANCE_BASE_API}/query_sets`;
export const SEARCH_RELEVANCE_EXPERIMENT_API = `${SEARCH_RELEVANCE_BASE_API}/experiments`;
export const SEARCH_RELEVANCE_JUDGMENT_API = `${SEARCH_RELEVANCE_BASE_API}/judgments`;
export const SEARCH_RELEVANCE_SEARCH_CONFIGURATION_API = `${SEARCH_RELEVANCE_BASE_API}/search_configurations`;

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

// Search Relevance node APIs
export const BASE_QUERYSET_NODE_API_PATH = `${BASE_NODE_API_PATH}/queryset`;
export const BASE_EXPERIMENT_NODE_API_PATH = `${BASE_NODE_API_PATH}/experiment`;
export const BASE_JUDGMENT_NODE_API_PATH = `${BASE_NODE_API_PATH}/judgment`;
export const BASE_SEARCH_CONFIG_NODE_API_PATH = `${BASE_NODE_API_PATH}/search_configuration`;



export const DEFAULT_HEADERS = {
'Content-Type': 'application/json',
Expand Down
94 changes: 75 additions & 19 deletions public/components/api/search_relevance_testing_page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,50 @@ import {
EuiCallOut,
EuiCodeBlock,
} from '@elastic/eui';
import { postQuerySet } from '../../services';
import { postQuerySet, getQuerySet } from '../../services';
import { CoreStart } from '../../../../../src/core/public';

export interface TestProps {
http: CoreStart['http'];
}
export const QuerySetTester = ({ http }: TestProps) => {
const [querySetId, setQuerySetId] = useState('');
const [response, setResponse] = useState(null);
const [isLoading, setIsLoading] = useState(false);
const [name, setName] = useState('');
const [description, setDescription] = useState('');
const [createResponse, setCreateResponse] = useState(null);
const [isCreateLoading, setIsCreateLoading] = useState(false);

const [id, setId] = useState('');
const [getResponse, setGetResponse] = useState(null);
const [isGetLoading, setIsGetLoading] = useState(false);
const [error, setError] = useState(null);

const handleSubmit = async (e) => {
const handleCreateSubmit = async (e) => {
e.preventDefault();
setIsLoading(true);
setIsCreateLoading(true);
setError(null);

try {
const result = await postQuerySet(querySetId, http);
setResponse(result);
const postResult = await postQuerySet(name, description, http);
setCreateResponse(postResult);
} catch (err) {
setError(err.message || 'An error occurred');
} finally {
setIsLoading(false);
setIsCreateLoading(false);
}
};

const handleGetSubmit = async (e) => {
e.preventDefault();
setIsGetLoading(true);
setError(null);

try {
const listResult = await getQuerySet(id, http);
setGetResponse(listResult);
} catch (err) {
setError(err.message || 'An error occurred');
} finally {
setIsGetLoading(false);
}
};

Expand All @@ -48,19 +68,43 @@ export const QuerySetTester = ({ http }: TestProps) => {
<h2>Query Set Tester</h2>
</EuiText>
<EuiSpacer size="m" />
<EuiForm component="form" onSubmit={handleSubmit}>
<EuiFormRow label="Query Set ID:">
<EuiForm component="form" onSubmit={handleCreateSubmit}>
<EuiFormRow label="Query Set Name:">
<EuiFieldText
placeholder="Enter Query Set Name"
value={name}
onChange={(e) => setName(e.target.value)}
fullWidth
/>
</EuiFormRow>
<EuiFormRow label="Query Set Description:">
<EuiFieldText
placeholder="Enter Query Set ID"
value={querySetId}
onChange={(e) => setQuerySetId(e.target.value)}
placeholder="Enter Query Set Description"
value={description}
onChange={(e) => setDescription(e.target.value)}
fullWidth
/>
</EuiFormRow>
<EuiSpacer size="m" />
<EuiButton type="submit" fill isLoading={isLoading}>
{isLoading ? 'Sending...' : 'Send Request'}
<EuiButton type="create submit" fill isCreateLoading={isCreateLoading}>
{isCreateLoading ? 'Sending...' : 'Send Create Request'}
</EuiButton>
<EuiSpacer size="m" />
</EuiForm>
<EuiForm component="form" onSubmit={handleGetSubmit}>
<EuiFormRow label="Get Query ID:">
<EuiFieldText
placeholder="Enter Get Query ID"
value={id}
onChange={(e) => setId(e.target.value)}
fullWidth
/>
</EuiFormRow>
<EuiSpacer size="m" />
<EuiButton type="get submit" fill isGetLoading={isGetLoading}>
{isCreateLoading ? 'Sending...' : 'Send Get Request'}
</EuiButton>
<EuiSpacer size="m" />
</EuiForm>
<EuiSpacer size="l" />

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

{response && (
{createResponse && (
<>
<EuiText>
<h3>Create Response:</h3>
</EuiText>
<EuiSpacer size="s" />
<EuiCodeBlock language="json" paddingSize="m" isCopyable>
{JSON.stringify(createResponse, null, 2)}
</EuiCodeBlock>
</>
)}

{getResponse && (
<>
<EuiText>
<h3>Response:</h3>
<h3>Get Response:</h3>
</EuiText>
<EuiSpacer size="s" />
<EuiCodeBlock language="json" paddingSize="m" isCopyable>
{JSON.stringify(response, null, 2)}
{typeof getResponse === 'string' ? getResponse : JSON.stringify(getResponse, null, 2)}
</EuiCodeBlock>
</>
)}
Expand Down
3 changes: 2 additions & 1 deletion public/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { PLUGIN_NAME, COMPARE_SEARCH_RESULTS_TITLE } from '../../common';
import { SearchRelevanceContextProvider } from '../contexts';
import { Home as QueryCompareHome } from './query_compare/home';
import { ExperimentPage } from './experiment';
import QuerySetTester from "./api/search_relevance_testing_page";

interface SearchRelevanceAppDeps {
notifications: CoreStart['notifications'];
Expand Down Expand Up @@ -156,7 +157,7 @@ export const SearchRelevanceApp = ({
setActionMenu={setActionMenu}
/>
) : (
<ExperimentPage application={application} chrome={chrome} />
<QuerySetTester http={http} />
)}
</>
);
Expand Down
128 changes: 125 additions & 3 deletions public/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,138 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { BASE_QUERYSET_NODE_API_PATH } from '../common';
import {
BASE_EXPERIMENT_NODE_API_PATH,
BASE_QUERYSET_NODE_API_PATH,
BASE_SEARCH_CONFIG_NODE_API_PATH,
} from '../common';

export const postQuerySet = async (id: string, http: any) => {
export const createQuerySet = async (name: string, description: string, http: any) => {
try {
return await http.post(`..${BASE_QUERYSET_NODE_API_PATH}`, {
body: JSON.stringify({
querySetId: id,
name,
description,
}),
});
} catch (e) {
return e;
}
};

export const postQuerySet = async (name: string, description: string, http: any) => {
try {
return await http.put(`..${BASE_QUERYSET_NODE_API_PATH}`, {
body: JSON.stringify({
name,
description,
}),
});
} catch (e) {
return e;
}
};

export const getQuerySet = async (id: string, http: any) => {
try {
const response = await http.get(`..${BASE_QUERYSET_NODE_API_PATH}/${id}`);
// TODO: add logs for debugging, please remove before release
// eslint-disable-next-line no-console
console.log('GET Response:', response);
return response;
} catch (e) {
// eslint-disable-next-line no-console
console.error('GET Error:', e);
return e;
}
};

export const listQuerySets = async (http: any) => {
try {
return await http.get(`..${BASE_QUERYSET_NODE_API_PATH}`);
} catch (e) {
return e;
}
};

export const deleteQuerySet = async (id: string, http: any) => {
try {
return await http.delete(`..${BASE_QUERYSET_NODE_API_PATH}/${id}`);
} catch (e) {
return e;
}
};

export const postSearchConfig = async (name: string, queryBody: string, http: any) => {
try {
return await http.put(`..${BASE_SEARCH_CONFIG_NODE_API_PATH}`, {
body: JSON.stringify({
name,
queryBody,
}),
});
} catch (e) {
return e;
}
};

export const getSearchConfig = async (id: string, http: any) => {
try {
return await http.get(`..${BASE_SEARCH_CONFIG_NODE_API_PATH}/${id}`);
} catch (e) {
return e;
}
};

export const listSearchConfig = async (http: any) => {
try {
return await http.get(`..${BASE_SEARCH_CONFIG_NODE_API_PATH}`);
} catch (e) {
return e;
}
};

export const deleteSearchConfig = async (id: string, http: any) => {
try {
return await http.delete(`..${BASE_SEARCH_CONFIG_NODE_API_PATH}/${id}`);
} catch (e) {
return e;
}
};

export const postExperiment = async (name: string, description: string, http: any) => {
try {
return await http.put(`..${BASE_EXPERIMENT_NODE_API_PATH}`, {
body: JSON.stringify({
name,
description,
}),
});
} catch (e) {
return e;
}
};

export const getExperiment = async (id: string, http: any) => {
try {
return await http.get(`..${BASE_EXPERIMENT_NODE_API_PATH}/${id}`);
} catch (e) {
return e;
}
};

export const listExperiment = async (http: any) => {
try {
return await http.get(`..${BASE_EXPERIMENT_NODE_API_PATH}`);
} catch (e) {
return e;
}
};

export const deleteExperiment = async (id: string, http: any) => {
try {
return await http.delete(`..${BASE_EXPERIMENT_NODE_API_PATH}/${id}`);
} catch (e) {
return e;
}
};
Loading
Loading