-
-
Notifications
You must be signed in to change notification settings - Fork 143
Hearing search index #1960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Hearing search index #1960
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { DateTime } from "luxon" | ||
import { db } from "../firebase" | ||
import { createSearchIndexer } from "../search" | ||
import { Hearing } from "../events/types" | ||
import { timeZone } from "../malegislature" | ||
|
||
type HearingSearchRecord = { | ||
id: string | ||
eventId: number | ||
title: string | ||
description?: string | ||
startsAt: number | ||
month: string | ||
year: number | ||
committeeCode?: string | ||
committeeName?: string | ||
locationName?: string | ||
locationCity?: string | ||
committeeChairs: string[] | ||
agendaTopics: string[] | ||
billNumbers: string[] | ||
billSlugs: string[] | ||
hasVideo: boolean | ||
} | ||
|
||
export const { | ||
syncToSearchIndex: syncHearingToSearchIndex, | ||
upgradeSearchIndex: upgradeHearingSearchIndex | ||
} = createSearchIndexer<HearingSearchRecord>({ | ||
sourceCollection: db.collection("events").where("type", "==", "hearing"), | ||
documentTrigger: "events/{eventId}", | ||
alias: "hearings", | ||
idField: "id", | ||
filter: data => data.type === "hearing", | ||
schema: { | ||
fields: [ | ||
{ name: "eventId", type: "int32", facet: false }, | ||
{ name: "title", type: "string", facet: false }, | ||
{ name: "description", type: "string", facet: false, optional: true }, | ||
{ name: "startsAt", type: "int64", facet: false }, | ||
{ name: "month", type: "string", facet: true }, | ||
{ name: "year", type: "int32", facet: true }, | ||
{ name: "committeeCode", type: "string", facet: true, optional: true }, | ||
{ name: "committeeName", type: "string", facet: true, optional: true }, | ||
{ name: "locationName", type: "string", facet: false, optional: true }, | ||
{ name: "locationCity", type: "string", facet: false, optional: true }, | ||
{ | ||
name: "committeeChairs", | ||
type: "string[]", | ||
facet: true | ||
}, | ||
{ name: "agendaTopics", type: "string[]", facet: false }, | ||
{ name: "billNumbers", type: "string[]", facet: false }, | ||
{ name: "billSlugs", type: "string[]", facet: false }, | ||
{ name: "hasVideo", type: "bool", facet: true } | ||
], | ||
default_sorting_field: "startsAt" | ||
}, | ||
convert: data => { | ||
const { | ||
content, | ||
startsAt: startsAtTimestamp, | ||
id, | ||
videoURL, | ||
committeeChairs | ||
} = Hearing.check(data) | ||
const startsAt = startsAtTimestamp.toMillis() | ||
const schedule = DateTime.fromMillis(startsAt, { zone: timeZone }) | ||
const bills = content.HearingAgendas?.flatMap(({ DocumentsInAgenda }) => | ||
DocumentsInAgenda.map(doc => ({ | ||
number: doc.BillNumber, | ||
slug: `${doc.GeneralCourtNumber}/${doc.BillNumber}` | ||
Comment on lines
+71
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. saving both the bill number and the slug for a more ergonomic/performant browse hearings page later on. |
||
})) | ||
) | ||
const committeeName = content.Name | ||
return { | ||
id: id, | ||
eventId: content.EventId, | ||
title: committeeName ?? `Hearing ${content.EventId}`, | ||
description: content.Description, | ||
startsAt, | ||
month: schedule.toFormat("LLLL"), | ||
year: schedule.year, | ||
committeeCode: content.HearingHost?.CommitteeCode, | ||
committeeName, | ||
locationName: content.Location?.LocationName, | ||
locationCity: content.Location?.City, | ||
committeeChairs, | ||
agendaTopics: content.HearingAgendas.map(agenda => agenda.Topic), | ||
billNumbers: bills.map(bill => bill.number), | ||
billSlugs: bills.map(bill => bill.slug), | ||
hasVideo: Boolean(videoURL) | ||
} | ||
} | ||
}) |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we create the helper |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ export type CollectionConfig<T extends BaseRecord = BaseRecord> = { | |
readonly documentTrigger: string | ||
readonly idField: string | ||
readonly convert: (data: DocumentData) => T | ||
readonly filter?: (data: DocumentData) => boolean | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. documentTrigger |
||
} | ||
|
||
const registered: CollectionConfig[] = [] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we only process events of type
hearing