Skip to content

Commit

Permalink
🐛 Exclude strikethrough text before indexing #1327 (#2073)
Browse files Browse the repository at this point in the history
  • Loading branch information
padms authored Feb 28, 2024
1 parent 2ba1fe6 commit a0e9a44
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
3 changes: 2 additions & 1 deletion search/IndexSanityContent/events/sanity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import * as TE from 'fp-ts/lib/TaskEither'
import { pipe } from 'fp-ts/lib/function'
import { SanityClient } from '@sanity/client'
import { Language, Page } from '../../common'
import { plainTextExcludingStrikeThrough } from '../../common/queryHelpers'

const query = /* groq */ `*[_type match "route_" + $lang + "*" && content->_type == "event" && !(_id in path("drafts.**")) && excludeFromSearch != true] {
"slug": slug.current,
_id,
"content": content->{
"title": pt::text(title),
"title": ${plainTextExcludingStrikeThrough('title')},
"ingress": pt::text(ingress),
"eventDate": eventDate.date,
"eventDescription": pt::text(content),
Expand Down
9 changes: 5 additions & 4 deletions search/IndexSanityContent/magazine/sanity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { pipe } from 'fp-ts/lib/function'
import { SanityClient } from '@sanity/client'
import { Language } from '../../common'
import { MappableAccordionType, MappableTextBlockType } from '../common/mappers'
import { plainTextExcludingStrikeThrough } from '../../common/queryHelpers'

export enum HeroTypes {
DEFAULT = 'default',
Expand All @@ -23,22 +24,22 @@ const publishDateTimeQuery = /* groq */ `
export const query = /* groq */ `*[_type == "magazine" && _lang == $lang && !(_id in path("drafts.**")) && excludeFromSearch != true] {
"slug": slug.current,
_id,
"title": pt::text(title),
"title": ${plainTextExcludingStrikeThrough('title')},
"type": _type,
"ingress": pt::text(ingress),
"textBlocks": content[_type == "textBlock"]{
"_key": _key,
"title": select(
isBigText == true =>
pt::text(bigTitle),
pt::text(title)
${plainTextExcludingStrikeThrough('bigTitle')},
${plainTextExcludingStrikeThrough('title')}
),
"ingress": pt::text(ingress),
"text": pt::text(text) // TODO: Do this manually to cover all cases
},
"accordions": content[_type == "accordion"] {
"_key": _key,
"title": pt::text(title),
"title": ${plainTextExcludingStrikeThrough('title')},
"ingress": pt::text(ingress),
"accordionItems":accordion[]{
"id": _key,
Expand Down
9 changes: 5 additions & 4 deletions search/IndexSanityContent/topic/sanity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@ import { pipe } from 'fp-ts/lib/function'
import { SanityClient } from '@sanity/client'
import { Language } from '../../common'
import { MappableAccordionType, MappableTextBlockType } from '../common/mappers'
import { plainTextExcludingStrikeThrough } from '../../common/queryHelpers'

export const query = /* groq */ `*[_type match "route_" + $lang + "*" && content->_type == "page" && !(_id in path("drafts.**")) && excludeFromSearch != true] {
"slug": slug.current,
_id,
"title": pt::text(content->title),
"title": ${plainTextExcludingStrikeThrough('content->title')},
"type": content->_type,
"textBlocks": content->content[_type == "textBlock"]{
"_key": _key,
"title": select(
isBigText == true =>
pt::text(bigTitle),
pt::text(title)
${plainTextExcludingStrikeThrough('bigTitle')},
${plainTextExcludingStrikeThrough('title')}
),
"ingress": pt::text(ingress),
"text": pt::text(text) // TODO: Do this manually to cover all cases
},
"accordions": content->content[_type == "accordion"] {
"_key": _key,
"title": pt::text(title),
"title": ${plainTextExcludingStrikeThrough('title')},
"ingress": pt::text(ingress),
"accordionItems":accordion[]{
"id": _key,
Expand Down
7 changes: 7 additions & 0 deletions search/common/queryHelpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const plainTextExcludingStrikeThrough = (blockTextField: string) => {
return /* groq */ `
pt::text(${blockTextField}[]{
...,
children[!("s" in marks)]
})`
}

0 comments on commit a0e9a44

Please sign in to comment.