Skip to content

Commit

Permalink
fix multi field search (#2380)
Browse files Browse the repository at this point in the history
it only checks fields with same analyzer,
so we need to use same analyzer for those full text
searchable fields

SDESK-6567
  • Loading branch information
petrjasek committed Sep 16, 2022
1 parent d6c6825 commit c3b3cc4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
1 change: 1 addition & 0 deletions prod_api/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
MONGO_URI,
ELASTICSEARCH_INDEX,
ELASTICSEARCH_URL,
ELASTICSEARCH_SETTINGS,
AMAZON_ACCESS_KEY_ID,
AMAZON_SECRET_ACCESS_KEY,
AMAZON_REGION,
Expand Down
31 changes: 20 additions & 11 deletions superdesk/metadata/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@
from typing import NamedTuple
from copy import deepcopy

from superdesk.resource import Resource, not_analyzed, not_indexed, not_enabled, text_with_keyword, not_dynamic
from superdesk.resource import (
Resource,
not_analyzed,
not_indexed,
not_enabled,
text_with_keyword,
not_dynamic,
string_with_analyzer,
)
from .packages import LINKED_IN_PACKAGES, PACKAGE
from eve.utils import config
from superdesk.utils import SuperdeskBaseEnum
Expand Down Expand Up @@ -241,14 +249,11 @@ class Formats(NamedTuple):
"abstract": {
"type": "string",
"nullable": True,
"mapping": string_with_analyzer,
},
"headline": {
"type": "string",
"mapping": {
"type": "string",
"analyzer": "html_field_analyzer",
"search_analyzer": "html_field_analyzer",
},
"mapping": string_with_analyzer,
},
"slugline": {
"type": "string",
Expand All @@ -259,12 +264,12 @@ class Formats(NamedTuple):
"phrase": {
"type": "string",
"analyzer": "phrase_prefix_analyzer",
"search_analyzer": "phrase_prefix_analyzer",
"fielddata": True,
},
"keyword": {
"type": "keyword",
},
"text": string_with_analyzer,
},
},
},
Expand All @@ -288,7 +293,7 @@ class Formats(NamedTuple):
"type": "integer",
"nullable": True,
},
"keywords": {"type": "list", "mapping": {"type": "string"}},
"keywords": {"type": "list", "mapping": string_with_analyzer},
"word_count": {"type": "integer"},
"priority": {"type": "integer", "nullable": True},
"urgency": {"type": "integer", "nullable": True},
Expand Down Expand Up @@ -326,10 +331,12 @@ class Formats(NamedTuple):
BYLINE: {
"type": "string",
"nullable": True,
"mapping": string_with_analyzer,
},
"ednote": {
"type": "string",
"nullable": True,
"mapping": string_with_analyzer,
},
"authors": {
"type": "list",
Expand All @@ -347,7 +354,7 @@ class Formats(NamedTuple):
},
},
},
"description_text": {"type": "string", "nullable": True},
"description_text": {"type": "string", "nullable": True, "mapping": string_with_analyzer},
# This is a description of the item as recieved from its source.
"archive_description": {"type": "string", "nullable": True},
"groups": {
Expand Down Expand Up @@ -382,11 +389,12 @@ class Formats(NamedTuple):
"body_html": {
"type": "string",
"nullable": True,
"mapping": {"type": "string", "analyzer": "html_field_analyzer", "search_analyzer": "html_field_analyzer"},
"mapping": string_with_analyzer,
},
"body_text": {
"type": "string",
"nullable": True,
"mapping": string_with_analyzer,
},
"dateline": {
"type": "dict",
Expand Down Expand Up @@ -461,7 +469,7 @@ class Formats(NamedTuple):
"allow_unknown": True,
"mapping": not_enabled,
},
"filemeta_json": {"type": "string"},
"filemeta_json": {"type": "string", "mapping": not_indexed},
"media_file": {"type": "string"},
"contents": {"type": "list"},
ASSOCIATIONS: {
Expand Down Expand Up @@ -571,6 +579,7 @@ class Formats(NamedTuple):
SIGN_OFF: {
"type": "string",
"nullable": True,
"mapping": string_with_analyzer,
},
# Desk and Stage Details
"task": {
Expand Down
2 changes: 2 additions & 0 deletions superdesk/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
not_analyzed = {"type": "string", "index": "not_analyzed"}
not_enabled = {"type": "object", "enabled": False} # noqa
not_dynamic = {"type": "object", "dynamic": False} # noqa
string_with_analyzer = {"type": "string", "analyzer": "html_field_analyzer"} # noqa
text_with_keyword = {
"type": "text",
"analyzer": "html_field_analyzer",
"fields": {
"keyword": {"type": "keyword"},
},
Expand Down

0 comments on commit c3b3cc4

Please sign in to comment.