diff --git a/gatsby-node.js b/gatsby-node.js index 7aaa4acd..7f0c7e65 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -9,13 +9,13 @@ const { DataFactory } = n3 const { namedNode } = DataFactory const path = require('path') const fs = require('fs-extra') -const flexsearch = require('flexsearch') const omitEmpty = require('omit-empty') const urlTemplate = require('url-template') const { i18n, getPath, getFilePath } = require('./src/common') const context = require('./src/context') const queries = require('./src/queries') const types = require('./src/types') +const { buildIndexAndScheme, addToIndex } = require('./src/searchIndex') require('dotenv').config() require('graceful-fs').gracefulify(require('fs')) @@ -123,8 +123,7 @@ exports.createPages = async ({ graphql, actions: { createPage } }) => { conceptSchemes.errors && console.error(conceptSchemes.errors) conceptSchemes.data.allConceptScheme.edges.forEach(async ({ node: conceptScheme }) => { - const index = flexsearch.create() - + let {index, indexScheme} = buildIndexAndScheme(languages) const conceptsInScheme = await graphql(queries.allConcept(conceptScheme.id, languages)) const embeddedConcepts = [] conceptsInScheme.data.allConcept.edges.forEach(({ node: concept }) => { @@ -174,7 +173,7 @@ exports.createPages = async ({ graphql, actions: { createPage } }) => { data: JSON.stringify(jsonas, null, 2) }) } - languages.forEach(language => index.add(concept.id, i18n(language)(concept.prefLabel))) + index = addToIndex(languages, concept, index) }) console.log("Built index", index.info()) @@ -202,6 +201,10 @@ exports.createPages = async ({ graphql, actions: { createPage } }) => { path: getFilePath(conceptScheme.id, 'index'), data: JSON.stringify(index.export(), null, 2) }) + createData({ + path: getFilePath(conceptScheme.id, 'index.scheme'), + data: JSON.stringify(indexScheme, null, 2) + }) }) // Build index pages diff --git a/src/components/nestedList.js b/src/components/nestedList.js index 7f5a2c35..2be17e74 100644 --- a/src/components/nestedList.js +++ b/src/components/nestedList.js @@ -103,8 +103,9 @@ const getNestedItems = item => { } const NestedList = ({ items, current, filter, highlight, language }) => { - const filteredItems = filter - ? items.filter(item => !filter || filter.some(filter => getNestedItems(item).includes(filter))) + const filterIds = filter ? filter.map(f => f.id) : null + const filteredItems = filterIds + ? items.filter(item => !filterIds || filterIds.some(filter => getNestedItems(item).includes(filter))) : items const t = i18n(language) @@ -116,7 +117,7 @@ const NestedList = ({ items, current, filter, highlight, language }) => { > {(item.narrower && item.narrower.length > 0) && (