Skip to content

Commit

Permalink
fix(web): Fix query for generic and team member lists (#17115)
Browse files Browse the repository at this point in the history
* Fix query for generic and team member lists

* Add tags to be searchable in gengeric list search

* Add title to be searchable in team member list search

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and RunarVestmann committed Jan 8, 2025
1 parent bec763d commit 059b816
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
12 changes: 4 additions & 8 deletions libs/cms/src/lib/cms.elasticsearch.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,9 @@ export class CmsElasticsearchService {
},
]

let queryString = input.queryString ? input.queryString.toLowerCase() : ''
let queryString = input.queryString
? input.queryString.trim().toLowerCase()
: ''

if (input.lang === 'is') {
queryString = queryString.replace('`', '')
Expand All @@ -520,6 +522,7 @@ export class CmsElasticsearchService {
query: queryString + '*',
fields: ['title^100', 'content'],
analyze_wildcard: true,
default_operator: 'and',
},
})

Expand All @@ -531,15 +534,8 @@ export class CmsElasticsearchService {
order: SortDirection.DESC,
},
},
// Sort items with equal values by ascending title order
{ 'title.sort': { order: SortDirection.ASC } },
]

// Order by score first in case there is a query string
if (queryString.length > 0 && queryString !== '*') {
sort.unshift('_score')
}

if (input.tags && input.tags.length > 0 && input.tagGroups) {
must = must.concat(
generateGenericTagGroupQueries(input.tags, input.tagGroups),
Expand Down
4 changes: 4 additions & 0 deletions libs/cms/src/lib/search/importers/genericListItem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export class GenericListItemSyncService
)
}

for (const tag of mapped.filterTags ?? []) {
contentSections.push(tag.title)
}

const content = contentSections.join(' ')

const tags: MappedData['tags'] =
Expand Down
15 changes: 12 additions & 3 deletions libs/cms/src/lib/search/importers/teamList.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,18 @@ export class TeamListSyncService implements CmsSyncProvider<ITeamList> {
const memberEntry = teamListEntry.fields.teamMembers?.find(
(m) => m.sys.id === member.id,
)
const content = memberEntry?.fields?.intro
? documentToPlainTextString(memberEntry.fields.intro)
: ''
const contentSection: string[] = []

contentSection.push(
memberEntry?.fields?.intro
? documentToPlainTextString(memberEntry.fields.intro)
: '',
)
if (member.title) {
contentSection.push(member.title)
}

const content = contentSection.join(' ')
teamMembers.push({
_id: member.id,
title: member.name,
Expand Down

0 comments on commit 059b816

Please sign in to comment.