Skip to content

Commit

Permalink
feat: APPS-2376 & APPS-2328 Add site-search-diacritics & stemming (#728)
Browse files Browse the repository at this point in the history
* feat: add stemming and diacritics to search

* delete extra filter

* feat: add default to analyzer
  • Loading branch information
jendiamond authored Aug 23, 2023
1 parent 202dca0 commit 613983c
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions modules/indexAliasGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,49 @@ const consola = require('consola')
consola.level = 5

export default function () {
this.nuxt.hook("generate:before", async() => {
this.nuxt.hook("generate:before", async () => {
// console.log(generator)
// console.log(generatorOptions)
// console.log("In generate before hook for generating a new ES index: "+ JSON.stringify(this.nuxt.options.publicRuntimeConfig))
const timeElapsed = Date.now()
const now = new Date(timeElapsed)
let esIndex = `${this.nuxt.options.publicRuntimeConfig.esIndexPrefix}-${now.toISOString().toLowerCase().replaceAll(":","-")}`
consola.debug("Index named:"+esIndex)

let esIndex = `${this.nuxt.options.publicRuntimeConfig.esIndexPrefix}-${now.toISOString().toLowerCase().replaceAll(":", "-")}`
consola.debug("Index named:" + esIndex)
//console.warn("Index path:"+`${this.nuxt.options.publicRuntimeConfig.esURL}/${esIndex}`)
//console.warn("Index write key:"+this.nuxt.options.privateRuntimeConfig.esWriteKey)
const response = await fetch(`${this.nuxt.options.publicRuntimeConfig.esURL}/${esIndex}`, {
headers: {
'Authorization': `ApiKey ${this.nuxt.options.privateRuntimeConfig.esWriteKey}`,
'Content-Type': 'application/json',
},
method: 'PUT'
method: 'PUT',
body: JSON.stringify({
settings: {
analysis: {
analyzer: {
default: {
type: "custom",
tokenizer: "standard",
filter: ["stemmer", "lowercase", "stop", "asciifolding"],
},
default_search: {
type: "custom",
tokenizer: "standard",
filter: ["stemmer", "lowercase", "stop", "asciifolding"],
}
},
}
}
}),
})
const body = await response.text()
try {
let testJson = JSON.parse(body)
let testJson = JSON.parse(body)
this.options.tempIndex = esIndex
this.nuxt.options.publicRuntimeConfig['esTempIndex'] = esIndex

consola.debug("Index created:"+JSON.stringify(testJson))
consola.debug("Index created:" + JSON.stringify(testJson))
} catch (err) {
consola.error("Error:", err)
consola.error("Response body:", body)
Expand Down

6 comments on commit 613983c

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸŽ‰ Published on https://www.library.ucla.edu as production
πŸš€ Deployed on https://64e6b0966084ad2858816d2f--uclalibrary.netlify.app

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸŽ‰ Published on https://www.library.ucla.edu as production
πŸš€ Deployed on https://64e6b219b6263b281672c6fb--uclalibrary.netlify.app

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸŽ‰ Published on https://www.library.ucla.edu as production
πŸš€ Deployed on https://64e711a527e0cb569a36fcca--uclalibrary.netlify.app

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸŽ‰ Published on https://www.library.ucla.edu as production
πŸš€ Deployed on https://64e7ba3235bb4f0093f7e3cb--uclalibrary.netlify.app

Please sign in to comment.