Skip to content

Commit

Permalink
Merge pull request #269 from skohub-io/161-search-by-notation
Browse files Browse the repository at this point in the history
161 search by notation
  • Loading branch information
sroertgen authored Sep 7, 2023
2 parents da37696 + 91ea6fd commit c0a59e7
Show file tree
Hide file tree
Showing 33 changed files with 741 additions and 153 deletions.
6 changes: 3 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module.exports = {
"node/no-path-concat": "off",
"react-hooks/rules-of-hooks": "off",
"no-console": "error",
"testing-library/await-async-query": "error",
"testing-library/no-await-sync-query": "error",
"testing-library/await-async-queries": "error",
"testing-library/no-await-sync-queries": "error",
"testing-library/no-debugging-utils": "warn",
"testing-library/no-dom-import": "off",
},
Expand All @@ -17,7 +17,7 @@ module.exports = {
{
files: ["**/cypress/**/*.cy.js"],
rules: {
"testing-library/await-async-query": 0,
"testing-library/await-async-queries": 0,
},
},
],
Expand Down
48 changes: 25 additions & 23 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,33 @@ jobs:
- run: npm run build --if-present
- run: npm run test

e2e:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
container: cypress/base:18.12.0
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: echo Using node version $(node --version)
- run: echo Using npm version $(npm --version)
- run: cypress/prepare-cypress-test.sh
- name: Cypress run
uses: cypress-io/[email protected]
with:
start: npm run develop -- -p 8000
wait-on: http://localhost:8000/index.de.html
config: baseUrl=http://localhost:8000
# disables because the action fails on github action but tests works locally
# e2e:
# runs-on: ubuntu-latest
# strategy:
# matrix:
# node-version: [18.x]
# steps:
# - name: Checkout
# uses: actions/checkout@v3
# - name: Use Node.js ${{ matrix.node-version }}
# uses: actions/setup-node@v3
# with:
# node-version: ${{ matrix.node-version }}
# - run: echo Using node version $(node --version)
# - run: echo Using npm version $(npm --version)
# - run: cypress/prepare-cypress-test.sh
# - name: Cypress run
# uses: cypress-io/github-action@v5
# with:
# browser: chrome
# headed: true
# start: npm run develop -- -p 8000
# wait-on: http://localhost:8000/index.de.html
# config: baseUrl=http://localhost:8000

docker:
needs: [build, e2e]
needs: [build]
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev' }}
runs-on: ubuntu-latest
steps:
Expand Down
9 changes: 8 additions & 1 deletion config.default.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
---
# see https://github.com/nextapps-de/flexsearch/tree/0.6.32#tokenizer for options
tokenizer: "full" # strict, forward, reverse, full
searchableAttributes:
- "prefLabel" # you should not delete this one
- "notation"
- "altLabel"
- "hiddenLabel"
- "example"
- "definition"
ui:
title: "SkoHub Vocabs" # Title is mandatory
logo: "skohub-signet-color.svg" # Path
Expand All @@ -26,4 +33,4 @@ ui:
font_family: "Ubuntu"
font_style: "normal"
font_weight: 700
name: "ubuntu-v20-latin-700"
name: "ubuntu-v20-latin-700"
1 change: 1 addition & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = defineConfig({
e2e: {
baseUrl: "http://localhost:8000",
specPattern: "cypress/e2e/**/*.cy.{js,jsx,ts,tsx}",
experimentalRunAllSpecs: true,
setupNodeEvents(on, config) {
// implement node event listeners here
},
Expand Down
20 changes: 20 additions & 0 deletions cypress/e2e/modal.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
describe("modal", () => {
// closing modal works
it("click on close closes the modal", () => {
cy.visit("/w3id.org/index.de.html")
cy.get("#settingsModal").should("not.be.visible")
cy.get("#settings").click()
cy.get("#settingsModal").should("be.visible")
cy.get("#closeModal").click()
cy.get("#settingsModal").should("not.be.visible")
})

it("click outside closes the modal", () => {
cy.visit("/w3id.org/index.de.html")
cy.get("#settingsModal").should("not.be.visible")
cy.get("#settings").click()
cy.get("#settingsModal").should("be.visible")
cy.get("#settingsModal").click(-5, -5)
cy.get("#settingsModal").should("not.be.visible")
})
})
65 changes: 63 additions & 2 deletions cypress/e2e/searchAndFilter.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,74 @@ describe("search and filter", () => {
it("search works after switching language", () => {
cy.visit("/w3id.org/index.de.html")

cy.contains("en").click()
cy.contains("en").click().wait(0) // eslint-disable-line

cy.get("span").contains("Konzept 2").should("not.exist")
cy.get(".currentLanguage").contains("en").should("exist")
// cy.get("span").contains("Konzept 1").should("not.exist")
cy.get("span").contains("Concept 1").should("exist")
cy.findByRole("textbox").type("Concept 2")
cy.get("span").contains("Concept 1").should("exist")
cy.get("span").contains("Concept 2").should("exist")
cy.get("span").contains("Concept 3").should("not.exist")
})

it("search works after switching concept schemes", () => {
cy.visit("/w3id.org/kim/hochschulfaechersystematik/scheme.en.html")
cy.findByRole("textbox").type("Mathema")

cy.get("span").contains("Mathematic").should("exist")

cy.visit("/w3id.org/cs-splitted-two-files/index.en.html")

cy.get("span").contains("Concept 1").should("exist")
})

it("turning on altLabel checkbox returns altLabel matches", () => {
cy.visit("/w3id.org/index.de.html")
cy.findByRole("textbox").type("Alternat")
cy.get("p").contains("Nothing found").should("exist")
cy.get("#settings").click()
cy.get("#altLabelCheckBox").click()
cy.get("#closeModal").click()
cy.get("span").contains("Konzept 1").should("exist")
})

it("turning on hiddenLabel checkbox returns hiddenLabel matches", () => {
cy.visit("/w3id.org/index.de.html")
cy.findByRole("textbox").type("Verstecktes")
cy.get("p").contains("Nothing found").should("exist")
cy.get("#settings").click()
cy.get("#hiddenLabelCheckBox").click()
cy.get("span").contains("Konzept 1").should("exist")
})

it("turning on notation checkbox returns notation matches", () => {
cy.visit("/w3id.org/index.de.html")
cy.findByRole("textbox").type("Notat")
cy.get("p").contains("Nothing found").should("exist")
cy.get("#settings").click()
cy.get("#notationCheckBox").click()
cy.get("#closeModal").click()
cy.get("span").contains("Konzept 1").should("exist")
})

it("turning on definition checkbox returns definition matches", () => {
cy.visit("/w3id.org/index.de.html")
cy.findByRole("textbox").type("Meine Defi")
cy.get("p").contains("Nothing found").should("exist")
cy.get("#settings").click()
cy.get("#definitionCheckBox").click()
cy.get("#closeModal").click()
cy.get("span").contains("Konzept 1").should("exist")
})

it("turning on example checkbox returns example matches", () => {
cy.visit("/w3id.org/index.de.html")
cy.findByRole("textbox").type("Beis")
cy.get("p").contains("Nothing found").should("exist")
cy.get("#settings").click()
cy.get("#exampleCheckBox").click()
cy.get("#closeModal").click()
cy.get("span").contains("Konzept 1").should("exist")
})
})
1 change: 1 addition & 0 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
colors: config.colors,
logo: config.logo,
fonts: config.fonts,
searchableAttributes: config.searchableAttributes,
},
pathPrefix: `${process.env.BASEURL || ""}`,
plugins: [
Expand Down
50 changes: 40 additions & 10 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { DataFactory } = n3
const { namedNode } = DataFactory
const path = require("path")
const fs = require("fs-extra")
const { Index } = require("flexsearch")
const { Index, Document } = require("flexsearch")
const omitEmpty = require("omit-empty")
const { i18n, getFilePath, parseLanguages } = require("./src/common")
const context = require("./src/context")
Expand Down Expand Up @@ -88,10 +88,6 @@ const exportIndex = (index, conceptScheme, language) => {
path,
data: data !== undefined ? data : "",
})
// fs.writeFileSync(
// `${searchIndexPath}${key}.json`,
// data !== undefined ? (data) : ""
// );
})
}

Expand Down Expand Up @@ -272,9 +268,22 @@ exports.createPages = async ({ graphql, actions: { createPage } }) => {
const languagesOfCS = languagesByCS[conceptScheme.id]
const indexes = Object.fromEntries(
[...languagesOfCS].map((l) => {
const index = new Index({
const index = new Document({
tokenize: tokenizer,
charset: "latin",
id: "id",
document: {
id: "id",
// store: ["prefLabel", "altLabel"], /* not working when importing, bug in flexsearch */
index: [
"notation",
"prefLabel",
"altLabel",
"hiddenLabel",
"definition",
"example",
],
},
})
return [l, index]
})
Expand Down Expand Up @@ -322,11 +331,32 @@ exports.createPages = async ({ graphql, actions: { createPage } }) => {
data: JSON.stringify(jsonld, null, 2),
})
}
languagesOfCS.forEach((language) =>
indexes[language].add(concept.id, i18n(language)(concept.prefLabel))
)
// add labels to index
languagesOfCS.forEach((language) => {
const document = {
id: concept.id,
prefLabel: i18n(language)(concept.prefLabel),
...(concept.altLabel &&
Object.hasOwn(concept.altLabel, language) && {
altLabel: i18n(language)(concept.altLabel),
}),
...(concept.hiddenLabel &&
Object.hasOwn(concept.hiddenLabel, language) && {
hiddenLabel: i18n(language)(concept.hiddenLabel),
}),
...(concept.definition &&
Object.hasOwn(concept.definition, language) && {
definition: i18n(language)(concept.definition),
}),
...(concept.example &&
Object.hasOwn(concept.example, language) && {
example: i18n(language)(concept.example),
}),
notation: concept.notation,
}
indexes[language].add(document)
})
})

languagesOfCS.forEach((language) =>
createPage({
path: getFilePath(conceptScheme.id, `${language}.html`),
Expand Down
8 changes: 5 additions & 3 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ const getDomId = (url) => {

/**
* Parses languages from a json ld graph (Concept or Concept Scheme)
* @param {array} json
* @param {array} graph
* @returns {array} languages - found languages
*/
const parseLanguages = (json) => {
const parseLanguages = (graph) => {
const languages = new Set()
const parse = (arrayOfObj) => {
for (let obj of arrayOfObj) {
Expand All @@ -80,7 +80,7 @@ const parseLanguages = (json) => {
obj?.narrower && parse(obj.narrower)
}
}
parse(json)
parse(graph)
return languages
}

Expand Down Expand Up @@ -119,6 +119,8 @@ const loadConfig = (configFile, defaultFile) => {
tokenizer: userConfig.tokenizer || defaults.tokenizer,
colors: userConfig.ui.colors || defaults.ui.colors,
fonts: userConfig.ui.fonts || defaults.ui.fonts,
searchableAttributes:
userConfig.searchableAttributes || defaults.searchableAttributes,
}

// check if all relevant colors are contained, otherwise use default colors
Expand Down
Loading

0 comments on commit c0a59e7

Please sign in to comment.