Skip to content

Commit

Permalink
[SDESK-7062] Add Event, Planning & Coverages to autocomplete suggesti…
Browse files Browse the repository at this point in the history
…ons (#1861)

* [SDESK-7062] Add Event, Planning & Coverages to autocomplete suggestions

* fix slugline schemas

* Add behave tests

* Add `count` to response

* Remove `.fireq` file
  • Loading branch information
MarkLark86 authored Oct 16, 2023
1 parent 29b9937 commit 363bffc
Show file tree
Hide file tree
Showing 6 changed files with 403 additions and 15 deletions.
3 changes: 0 additions & 3 deletions .fireq.json

This file was deleted.

230 changes: 230 additions & 0 deletions server/features/search_autocomplete.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
Feature: Planning autocomplete
Background: Setup config
Given config update
"""
{
"ARCHIVE_AUTOCOMPLETE": true,
"ARCHIVE_AUTOCOMPLETE_DAYS": 999
}
"""

@auth
Scenario: Get distinct planning sluglines
Given "planning"
"""
[{
"_id": "plan1",
"guid": "plan1",
"versioncreated": "#DATE#",
"state": "scheduled",
"pubstatus": "usable",
"slugline": "planning-1",
"language": "en",
"languages": ["en", "fr", "de"],
"planning_date": "2021-01-11T16:00:00.000Z",
"translations": [
{"field": "slugline", "language": "en", "value": "planning-en-test"},
{"field": "slugline", "language": "de", "value": "planning-de-test"}
]
}]
"""
# Suggests only the value in translations if populated
When we get "/archive_autocomplete?field=slugline&language=en"
Then we get list with 1 items
"""
{"_items": [{"value": "planning-en-test", "count": 1}]}
"""
# Suggests base field if language translation not populated
When we get "/archive_autocomplete?field=slugline&language=fr"
Then we get list with 1 items
"""
{"_items": [{"value": "planning-1", "count": 1}]}
"""

@auth
Scenario: Get distinct coverage sluglines
Given "planning"
"""
[{
"_id": "plan1",
"guid": "plan1",
"versioncreated": "#DATE#",
"state": "scheduled",
"pubstatus": "usable",
"slugline": "planning-1",
"language": "en",
"languages": ["en", "fr", "de"],
"planning_date": "2021-01-11T16:00:00.000Z",
"coverages": [{
"planning": {"language": "en", "slugline": "coverage-en-slugline"},
"workflow_state": "draft",
"news_coverage_status": {"qcode": "ncostat:int"}
}, {
"planning": {"language": "fr", "slugline": "coverage-fr-slugline"},
"workflow_state": "draft",
"news_coverage_status": {"qcode": "ncostat:int"}
}]
}]
"""
# Suggests both Planning and Coverage sluglines
When we get "/archive_autocomplete?field=slugline&language=en"
Then we get list with 2 items
"""
{"_items": [
{"value": "planning-1", "count": 1},
{"value": "coverage-en-slugline", "count": 1}
]}
"""

@auth
Scenario: Get distinct event sluglines
Given "events"
"""
[{
"_id": "event1",
"state": "scheduled",
"pubstatus": "usable",
"slugline": "event-1",
"language": "en",
"languages": ["en", "fr", "de"],
"dates": {
"start": "2025-01-03T00:00:00+0000",
"end": "2025-01-04T00:00:00+0000"
},
"translations": [
{"field": "slugline", "language": "en", "value": "event-en-test"},
{"field": "slugline", "language": "de", "value": "event-de-test"}
]
}]
"""
# Suggests only the value in translations if populated
When we get "/archive_autocomplete?field=slugline&language=en"
Then we get list with 1 items
"""
{"_items": [{"value": "event-en-test", "count": 1}]}
"""
# Suggests base field if language translation not populated
When we get "/archive_autocomplete?field=slugline&language=fr"
Then we get list with 1 items
"""
{"_items": [{"value": "event-1", "count": 1}]}
"""

@auth
Scenario: Can control what resources are used for suggestions
Given "planning"
"""
[{
"_id": "plan1",
"guid": "plan1",
"versioncreated": "#DATE#",
"state": "scheduled",
"pubstatus": "usable",
"slugline": "planning-1",
"language": "en",
"languages": ["en", "fr", "de"],
"planning_date": "2021-01-11T16:00:00.000Z",
"translations": [
{"field": "slugline", "language": "en", "value": "planning-en-test"},
{"field": "slugline", "language": "de", "value": "planning-de-test"}
]
}]
"""
Given "events"
"""
[{
"_id": "event1",
"state": "scheduled",
"pubstatus": "usable",
"slugline": "event-1",
"language": "en",
"languages": ["en", "fr", "de"],
"dates": {
"start": "2025-01-03T00:00:00+0000",
"end": "2025-01-04T00:00:00+0000"
},
"translations": [
{"field": "slugline", "language": "en", "value": "event-en-test"},
{"field": "slugline", "language": "de", "value": "event-de-test"}
]
}]
"""
# Provides suggestions from all resources if argument not provided
When we get "/archive_autocomplete?field=slugline&language=en"
Then we get list with 2 items
"""
{"_items": [
{"value": "planning-en-test", "count": 1},
{"value": "event-en-test", "count": 1}
]}
"""
# Doesn't provide planning suggestions if ``planning`` not in resources argument
When we get "/archive_autocomplete?field=slugline&language=en&resources=archive"
Then we get list with 0 items
# Provides planning suggestions if ``planning`` is in resources argument
When we get "/archive_autocomplete?field=slugline&language=en&resources=archive,planning"
Then we get list with 1 items
"""
{"_items": [{"value": "planning-en-test", "count": 1}]}
"""
# Doesn't provide event suggestions if ``events`` not in resources argument
When we get "/archive_autocomplete?field=slugline&language=en&resources=archive"
Then we get list with 0 items
# Provides event suggestions if ``events`` is in resources argument
When we get "/archive_autocomplete?field=slugline&language=en&resources=archive,events"
Then we get list with 1 items
"""
{"_items": [{"value": "event-en-test", "count": 1}]}
"""

@auth
Scenario: Counts suggestions from multiple resources
Given "planning"
"""
[{
"_id": "plan1",
"guid": "plan1",
"versioncreated": "#DATE#",
"state": "scheduled",
"pubstatus": "usable",
"slugline": "package-1",
"language": "en",
"languages": ["en", "fr", "de"],
"planning_date": "2021-01-11T16:00:00.000Z",
"translations": [
{"field": "slugline", "language": "en", "value": "package-en-slugline"},
{"field": "slugline", "language": "de", "value": "package-de-slugline"}
],
"coverages": [{
"planning": {"language": "en", "slugline": "package-en-slugline"},
"workflow_state": "draft",
"news_coverage_status": {"qcode": "ncostat:int"}
}]
}]
"""
Given "events"
"""
[{
"_id": "event1",
"state": "scheduled",
"pubstatus": "usable",
"slugline": "package-1",
"language": "en",
"languages": ["en", "fr", "de"],
"dates": {
"start": "2025-01-03T00:00:00+0000",
"end": "2025-01-04T00:00:00+0000"
},
"translations": [
{"field": "slugline", "language": "en", "value": "package-en-slugline"},
{"field": "slugline", "language": "de", "value": "package-de-slugline"}
]
}]
"""
When we get "/archive_autocomplete?field=slugline&language=en"
Then we get list with 1 items
"""
{"_items": [
{"value": "package-en-slugline", "count": 3}
]}
"""
2 changes: 2 additions & 0 deletions server/planning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import planning.io # noqa
from planning.planning_download import init_app as init_planning_download_app
from planning.planning_locks import init_app as init_planning_locks_app
from planning.search.planning_autocomplete import init_app as init_planning_autocomplete_app

__version__ = "2.7.0-dev"

Expand Down Expand Up @@ -112,6 +113,7 @@ def init_app(app):
init_validator_app(app)
init_planning_download_app(app)
init_planning_locks_app(app)
init_planning_autocomplete_app(app)

superdesk.register_resource(
"planning_article_export",
Expand Down
2 changes: 1 addition & 1 deletion server/planning/events/events_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@
"properties": {
"field": not_analyzed,
"language": not_analyzed,
"value": string_with_analyzer,
"value": metadata_schema["slugline"]["mapping"],
},
},
},
Expand Down
13 changes: 2 additions & 11 deletions server/planning/planning/planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,7 @@ def duplicate_xmp_file(self, coverage):
"properties": {
"field": not_analyzed,
"language": not_analyzed,
"value": string_with_analyzer,
"value": metadata_schema["slugline"]["mapping"],
},
},
},
Expand Down Expand Up @@ -1570,16 +1570,7 @@ def duplicate_xmp_file(self, coverage):
"planning": {
"type": "object",
"properties": {
"slugline": {
"type": "string",
"fields": {
"phrase": {
"type": "string",
"analyzer": "phrase_prefix_analyzer",
"search_analyzer": "phrase_prefix_analyzer",
}
},
},
"slugline": metadata_schema["slugline"]["mapping"],
},
},
"assigned_to": assigned_to_schema["mapping"],
Expand Down
Loading

0 comments on commit 363bffc

Please sign in to comment.