From 6f3e2d67d1f043bba3329c53c4693fb7a3eea298 Mon Sep 17 00:00:00 2001 From: Ralph Ursprung Date: Fri, 11 Oct 2024 17:30:30 +0200 Subject: [PATCH] add phone number analysis plugin this is part of opensearch-project/OpenSearch#11326. the actual implementation was done opensearch-project/OpenSearch#15915. see the commit message on the PR for further details. the new test group `analysis` has been added so that it can later be extended with all other optional language analyzers (which are currently also not covered). note that the CI currently needs to fetch the image from `opensearchstaging` as 2.18.0 hasn't been released yet. the `hub` and `ref` config can be removed once 2.18.0 has been released. Signed-off-by: Ralph Ursprung --- .github/workflows/test-spec.yml | 4 +++ CHANGELOG.md | 1 + spec/schemas/_common.analysis.yaml | 12 +++++++ tests/plugins/analysis/Dockerfile | 6 ++++ tests/plugins/analysis/docker-compose.yml | 17 +++++++++ .../indices/analyze/analyzer/phone.yaml | 36 +++++++++++++++++++ 6 files changed, 76 insertions(+) create mode 100644 tests/plugins/analysis/Dockerfile create mode 100644 tests/plugins/analysis/docker-compose.yml create mode 100644 tests/plugins/analysis/indices/analyze/analyzer/phone.yaml diff --git a/.github/workflows/test-spec.yml b/.github/workflows/test-spec.yml index a4c354c89..e1fad0b10 100644 --- a/.github/workflows/test-spec.yml +++ b/.github/workflows/test-spec.yml @@ -36,6 +36,10 @@ jobs: tests: routing - version: 2.16.0 tests: snapshot + - version: 2.18.0 + hub: opensearchstaging + ref: '@sha256:f311da085b968663fadf041bafc78b24dc21556f0726e625caf3560f7323a020' + tests: plugins/analysis - version: 2.17.0 tests: plugins/streaming - version: 2.17.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index c6fe8e15b..ae2bbcf8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -102,6 +102,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Added `404` response for `DELETE /{index}`, `GET /{index}/_doc/{id}`, `DELETE /{index}/_doc/{id}` ([#589](https://github.com/opensearch-project/opensearch-api-specification/pull/589)) - Added ability to pass `InlineScript` as a simple string ([#605](https://github.com/opensearch-project/opensearch-api-specification/pull/605)) - Added `config_id` and `config_id_list` to `/_plugins/_notifications/configs` query parameters ([#594](https://github.com/opensearch-project/opensearch-api-specification/pull/594)) +- Added documentation & test for `analysis-phonenumber` plugin ([#609](https://github.com/opensearch-project/opensearch-api-specification/pull/609)) ### Changed diff --git a/spec/schemas/_common.analysis.yaml b/spec/schemas/_common.analysis.yaml index 9cae913b6..07be175e7 100644 --- a/spec/schemas/_common.analysis.yaml +++ b/spec/schemas/_common.analysis.yaml @@ -27,6 +27,7 @@ components: - $ref: '#/components/schemas/DutchAnalyzer' - $ref: '#/components/schemas/SmartcnAnalyzer' - $ref: '#/components/schemas/CjkAnalyzer' + - $ref: '#/components/schemas/PhoneAnalyzer' CustomAnalyzer: type: object properties: @@ -367,6 +368,17 @@ components: $ref: '#/components/schemas/StopWords' stopwords_path: type: string + PhoneAnalyzer: + type: object + properties: + type: + type: string + enum: + - phone + - phone-search + phone-region: + type: string + description: Optional ISO 3166 country code, defaults to "ZZ" (unknown region). CharFilter: oneOf: - title: name diff --git a/tests/plugins/analysis/Dockerfile b/tests/plugins/analysis/Dockerfile new file mode 100644 index 000000000..a96cb3b65 --- /dev/null +++ b/tests/plugins/analysis/Dockerfile @@ -0,0 +1,6 @@ +ARG OPENSEARCH_DOCKER_HUB_PROJECT +ARG OPENSEARCH_VERSION +ARG OPENSEARCH_DOCKER_REF + +FROM ${OPENSEARCH_DOCKER_HUB_PROJECT}/opensearch:${OPENSEARCH_VERSION}${OPENSEARCH_DOCKER_REF} +RUN ./bin/opensearch-plugin install -b analysis-phonenumber diff --git a/tests/plugins/analysis/docker-compose.yml b/tests/plugins/analysis/docker-compose.yml new file mode 100644 index 000000000..0f4c7da5d --- /dev/null +++ b/tests/plugins/analysis/docker-compose.yml @@ -0,0 +1,17 @@ +version: '3' + +services: + opensearch-cluster: + build: + context: . + args: + - OPENSEARCH_DOCKER_HUB_PROJECT=${OPENSEARCH_DOCKER_HUB_PROJECT:-opensearchproject} + - OPENSEARCH_DOCKER_REF=${OPENSEARCH_DOCKER_REF} + - OPENSEARCH_VERSION=${OPENSEARCH_VERSION:-latest} + ports: + - 9200:9200 + - 9600:9600 + environment: + - OPENSEARCH_INITIAL_ADMIN_PASSWORD=${OPENSEARCH_PASSWORD:-myStrongPassword123!} + - OPENSEARCH_JAVA_OPTS=${OPENSEARCH_JAVA_OPTS} + - discovery.type=single-node diff --git a/tests/plugins/analysis/indices/analyze/analyzer/phone.yaml b/tests/plugins/analysis/indices/analyze/analyzer/phone.yaml new file mode 100644 index 000000000..083eea6bd --- /dev/null +++ b/tests/plugins/analysis/indices/analyze/analyzer/phone.yaml @@ -0,0 +1,36 @@ +$schema: ../../../../../json_schemas/test_story.schema.yaml + +description: Test /{index}/_analyze for the phone and phone-search analyzers. +prologues: + - path: /example-phone + method: PUT + request: + payload: + settings: + index: + analysis: + analyzer: + phone-ch: + type: phone + phone-region: CH + phone-search-ch: + type: phone-search + phone-region: CH +epilogues: + - path: /example-phone + method: DELETE + status: [200, 404] +chapters: + - synopsis: Analyze phone number. + path: /{index}/_analyze + method: POST + parameters: + index: example-phone + request: + payload: + text: +41 60 555 12 34 + response: + status: 200 + payload: + tokens: + - token: 605551234