Skip to content

Commit

Permalink
Merge branch '2.x' into backport-143-plus-177-to-2.x
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chu <clingzhi@amazon.com>
  • Loading branch information
noCharger committed May 26, 2023
2 parents 9be342e + d9e8c2d commit 5ee88ec
Show file tree
Hide file tree
Showing 20 changed files with 638 additions and 104 deletions.
33 changes: 26 additions & 7 deletions .github/workflows/draft-release-notes-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,38 @@ name: Release Drafter

on:
push:
# branches to consider in the event; optional, defaults to all
branches:
- main
- master
# pull_request event is required only for autolabeler
pull_request:
# Only following types are handled by the action, but one can default to all as well
types: [opened, reopened, synchronize]
# pull_request_target event is required for autolabeler to support PRs from forks
# pull_request_target:
# types: [opened, reopened, synchronize]

permissions:
contents: read

jobs:
update_release_draft:
name: Update draft release notes
permissions:
# write permission is required to create a github release
contents: write
# write permission is required for autolabeler
# otherwise, read permission is required at least
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Update draft release notes
uses: release-drafter/release-drafter@v5
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
with:
config-name: draft-release-notes-config.yml
name: Version (set here)
tag: (None)
disable-autolabeler: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}



1 change: 1 addition & 0 deletions .github/workflows/test-and-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on: [pull_request, push]
env:
PLUGIN_NAME: dashboards-search-relevance


jobs:
build:
strategy:
Expand Down
11 changes: 11 additions & 0 deletions .opensearch_dashboards-plugin-helpers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"serverSourcePatterns": [
"package.json",
"tsconfig.json",
"yarn.lock",
".yarnrc",
"{lib,public,server,webpackShims,translations,utils,models,common}/**/*",
"!__tests__",
"config.ts"
]
}
4 changes: 3 additions & 1 deletion MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ This document contains a list of maintainers in this repo. See [opensearch-proje
| ------------ | ------------------------------------- | ----------- |
| Mark Cohen | [macohen](https://github.com/macohen) | Amazon |
| Michael Froh | [msfroh](https://github.com/msfroh) | Amazon |
| Mingshi Liu | [mingshl](https://github.com/mingshl) | Amazon |
| Mingshi Liu | [mingshl](https://github.com/mingshl) | Amazon |
| Louis Chu | [noCharger](https://github.com/noCharger) | Amazon |
| Sean Li | [sejli](https://github.com/sejli) | Amazon |
1 change: 1 addition & 0 deletions common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export const PLUGIN_NAME = 'Search Relevance';
export enum ServiceEndpoints {
GetIndexes = '/api/relevancy/search/indexes',
GetSearchResults = '/api/relevancy/search',
GetStats = '/api/relevancy/stats',
}
17 changes: 17 additions & 0 deletions config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { schema, TypeOf } from '@osd/config-schema';

import { METRIC_INTERVAL, DEFAULT_WINDOW_SIZE } from './server/metrics';

export const configSchema = schema.object({
metrics: schema.object({
metricInterval: schema.number({ defaultValue: METRIC_INTERVAL.ONE_MINUTE }),
windowSize: schema.number({ min: 2, max: 10, defaultValue: DEFAULT_WINDOW_SIZE }),
}),
});

export type SearchRelevancePluginConfigType = TypeOf<typeof configSchema>;
6 changes: 3 additions & 3 deletions opensearch_dashboards.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"id": "searchRelevanceDashboards",
"version": "2.5.0.0",
"opensearchDashboardsVersion": "2.5.0",
"version": "2.8.0.0",
"opensearchDashboardsVersion": "2.8.0",
"server": true,
"ui": true,
"requiredPlugins": [
"navigation"
]
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "searchRelevanceDashboards",
"version": "2.5.0.0",
"version": "2.8.0.0",
"main": "./public/index.ts",
"license": "Apache-2.0",
"scripts": {
Expand All @@ -22,4 +22,4 @@
"glob-parent": "^6.0.1",
"qs": "~6.5.3"
}
}
}
118 changes: 65 additions & 53 deletions public/components/query_compare/search_result/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,85 +38,97 @@ export const SearchResult = ({ http }: SearchResultProps) => {
} = useSearchRelevanceContext();

const onClickSearch = () => {
const queryError1: QueryError = { ...initialQueryErrorState };
const queryError2: QueryError = { ...initialQueryErrorState };
const queryErrors = [{ ...initialQueryErrorState }, { ...initialQueryErrorState }];
const jsonQueries = [{}, {}];

validateQuery(selectedIndex1, queryString1, queryErrors[0]);
jsonQueries[0] = rewriteQuery(searchBarValue, queryString1, queryErrors[0]);

validateQuery(selectedIndex2, queryString2, queryErrors[1]);
jsonQueries[1] = rewriteQuery(searchBarValue, queryString2, queryErrors[1]);

handleQuery(jsonQueries, queryErrors);
};

const validateQuery = (selectedIndex: string, queryString: string, queryError: QueryError) => {
// Check if select an index
if (!selectedIndex1.length) {
queryError1.selectIndex = 'An index is required. Select an index.';
}
if (!selectedIndex2.length) {
queryError2.selectIndex = 'An index is required. Select an index.';
if (!selectedIndex.length) {
queryError.selectIndex = 'An index is required. Select an index.';
}

// Check if query string is empty
if (!queryString1.length) {
queryError1.queryString = QueryStringError.empty;
}
if (!queryString2.length) {
queryError2.queryString = QueryStringError.empty;
if (!queryString.length) {
queryError.queryString = QueryStringError.empty;
}
};

// Check if query string is valid
let jsonQuery1 = {};
let jsonQuery2 = {};
if (queryString1.trim().length > 0) {
const rewriteQuery = (searchBarValue: string, queryString: string, queryError: QueryError) => {
if (queryString.trim().length > 0) {
try {
jsonQuery1 = JSON.parse(queryString1.replace(/%SearchText%/g, searchBarValue));
return JSON.parse(queryString.replace(/%SearchText%/g, searchBarValue));
} catch {
queryError1.queryString = QueryStringError.invalid;
}
}
if (queryString2.trim().length > 0) {
try {
jsonQuery2 = JSON.parse(queryString2.replace(/%SearchText%/g, searchBarValue));
} catch {
queryError2.queryString = QueryStringError.invalid;
queryError.queryString = QueryStringError.invalid;
}
}
};

const handleQuery = (jsonQueries: any, queryErrors: QueryError[]) => {
let requestBody = {};

// Handle query1
if (queryError1.queryString.length || queryError1.selectIndex.length) {
setQueryError1(queryError1);
if (queryErrors[0].queryString.length || queryErrors[0].selectIndex.length) {
setQueryError1(queryErrors[0]);
setQueryResult1({} as any);
updateComparedResult1({} as any);
} else if (!queryError1.queryString.length && !queryError1.selectIndex.length) {
http
.post(ServiceEndpoints.GetSearchResults, {
body: JSON.stringify({ index: selectedIndex1, ...jsonQuery1 }),
})
.then((res) => {
setQueryResult1(res);
updateComparedResult1(res);
})
.catch((error: Error) => {
setQueryError1({
...queryError1,
queryString: error.body.message,
});
console.error(error);
});
} else if (!queryErrors[0].queryString.length && !queryErrors[0].selectIndex.length) {
requestBody = {
query1: { index: selectedIndex1, ...jsonQueries[0] },
};
}

// Handle query2
if (queryError2.queryString.length || queryError2.selectIndex.length) {
setQueryError2(queryError2);
if (queryErrors[1].queryString.length || queryErrors[1].selectIndex.length) {
setQueryError2(queryErrors[1]);
setQueryResult2({} as any);
updateComparedResult2({} as any);
} else if (!queryError2.queryString.length && !queryError2.selectIndex.length) {
} else if (!queryErrors[1].queryString.length && !queryErrors[1].selectIndex.length) {
requestBody = {
...requestBody,
query2: { index: selectedIndex2, ...jsonQueries[1] },
};
}

if (Object.keys(requestBody).length !== 0) {
http
.post(ServiceEndpoints.GetSearchResults, {
body: JSON.stringify({ index: selectedIndex2, ...jsonQuery2 }),
body: JSON.stringify(requestBody),
})
.then((res) => {
setQueryResult2(res);
updateComparedResult2(res);
if (res.result1) {
setQueryResult1(res.result1);
updateComparedResult1(res.result1);
}

if (res.result2) {
setQueryResult2(res.result2);
updateComparedResult2(res.result2);
}

if (res.errorMessage1) {
setQueryError1({
...queryErrors[0],
queryString: res.errorMessage1,
});
}

if (res.errorMessage2) {
setQueryError2({
...queryErrors[1],
queryString: res.errorMessage2,
});
}
})
.catch((error: Error) => {
setQueryError2({
...queryError2,
queryString: error.body.message,
});
console.error(error);
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## What's Changed
### Features
* [Feature] Exposing Metrics for Search Comparison Tool by @noCharger in https://github.com/opensearch-project/dashboards-search-relevance/pull/162

### Bug Fixes & Maintainence
* [Bug][Build] export config file by @kavilla in https://github.com/opensearch-project/dashboards-search-relevance/pull/183
* removing stats.yml until an alternate can be found that can publish P… by @macohen in https://github.com/opensearch-project/dashboards-search-relevance/pull/110

## New Maintainers
* New Maintainers - Sean Li and Louis Chu by @macohen in https://github.com/opensearch-project/dashboards-search-relevance/pull/172
## New Contributors
* @kavilla made their first contribution in https://github.com/opensearch-project/dashboards-search-relevance/pull/183

**Full Changelog**: https://github.com/opensearch-project/dashboards-search-relevance/commits/2.7.0.0

8 changes: 5 additions & 3 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { PluginInitializerContext } from '../../../src/core/server';
import { PluginConfigDescriptor, PluginInitializerContext } from '../../../src/core/server';
import { SearchRelevancePlugin } from './plugin';
import { configSchema, SearchRelevancePluginConfigType } from '../config';

// This exports static code and TypeScript types,
// as well as, OpenSearch Dashboards Platform `plugin()` initializer.
export const config: PluginConfigDescriptor<SearchRelevancePluginConfigType> = {
schema: configSchema,
};

export function plugin(initializerContext: PluginInitializerContext) {
return new SearchRelevancePlugin(initializerContext);
Expand Down
23 changes: 23 additions & 0 deletions server/metrics/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export { MetricsServiceSetup, MetricsService } from './metrics_service';

export enum METRIC_INTERVAL {
ONE_SECOND = 1000,
ONE_MINUTE = 60000,
}

export const DEFAULT_WINDOW_SIZE = 3;

export enum METRIC_NAME {
SEARCH_RELEVANCE = 'search_relevance',
}

export enum METRIC_ACTION {
COMPARISON_SEARCH = 'comparison_search',
SINGLE_SEARCH = 'single_search',
FETCH_INDEX = 'fetch_index',
}
Loading

0 comments on commit 5ee88ec

Please sign in to comment.