Skip to content
This repository has been archived by the owner on Jun 22, 2023. It is now read-only.

Commit

Permalink
fix(search): register all searchable types with fulltext search dynam…
Browse files Browse the repository at this point in the history
…ically
  • Loading branch information
ChristiaanScheermeijer committed Mar 12, 2021
1 parent d08d995 commit 45bfb6e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/migrations/01-constraints.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { assertSchema } from 'neo4j-graphql-js'
import { schema } from '../schema'
import { info } from '../utils/logger'

/**
* @param {Transaction} transactions
Expand All @@ -26,11 +27,13 @@ export default async (transactions, driver) => {
// run the assertSchema which creates all constraints based on the @id directives
await assertSchema({ schema, driver, debug: false, dropExisting: true })

const searchableTypeMap = schema.getType('SearchableInterfaceType').getValues().map(value => value.name)
const searchableFieldsMap = schema.getType('SearchableMetadataFields').getValues().map(value => value.name)

const query = `CALL db.index.fulltext.createNodeIndex('metadataSearchFields', ${JSON.stringify(searchableTypeMap)}, ${JSON.stringify(searchableFieldsMap)})`

info(`Fulltext query: ${query}`)

// create index transaction
transactions.run(`
CALL db.index.fulltext.createNodeIndex('metadataSearchFields', ['Person', 'CreativeWork', 'Article', 'DigitalDocument',
'MediaObject', 'Review', 'AudioObject', 'DataDownload', 'Dataset', 'ImageObject', 'MusicComposition', 'MusicPlaylist',
'MusicRecording', 'VideoObject', 'Event', 'Organization', 'MusicGroup', 'Product', 'Place'], ['title', 'creator',
'description', 'subject'])
`)
transactions.run(query)
}
1 change: 1 addition & 0 deletions src/schema/enum.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum SearchableInterfaceType {
Action
Article
AudioObject
CreativeWork
DataDownload
Dataset
DigitalDocument
Expand Down

0 comments on commit 45bfb6e

Please sign in to comment.