Skip to content
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

feat: Auto update algolia index #488

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

szeckirjr
Copy link
Contributor

@szeckirjr szeckirjr commented Jul 8, 2023

Description

This PR adds a TS script to generate a new algolia index and update it so that search has latest data.
I got it to work with my own algolia account and it seems to be working if those are the only fields needed.

It also adds a GH Action script we can dispatch to update the specified term

Closes #444

image

Checklist

  • The code follows all style guidelines.
  • The code passes all required tests.
  • The code is documented.
  • The code includes tests.
  • I have self-reviewed my changes and have done QA.

@vercel
Copy link

vercel bot commented Jul 8, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
courseup ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 18, 2023 2:27am

@szeckirjr szeckirjr marked this pull request as ready for review July 8, 2023 01:49
@szeckirjr szeckirjr requested a review from a team as a code owner July 8, 2023 01:49
@szeckirjr szeckirjr requested a review from aomi July 8, 2023 01:49
functions/package.json Show resolved Hide resolved
.github/workflows/update-algolia.yaml Outdated Show resolved Hide resolved
Comment on lines +68 to +75
index
.saveObjects(coursesForIndex)
.then(({ objectIDs }) => {
console.log(objectIDs);
})
.catch((err) => {
console.log(err);
});
Copy link
Member

Choose a reason for hiding this comment

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

Are you going to update a single index by clearing it and then adding new data or doing this? iirc if you say run this twice in succession you'll have duplicate records in the index. I think the objectID should make it so it doesn't but just want to check in.

Copy link
Member

Choose a reason for hiding this comment

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

What is the plan for stale courses? ie. courses that don't exist anymore cause this will make it so some will linger.

Copy link
Contributor Author

@szeckirjr szeckirjr Jul 18, 2023

Choose a reason for hiding this comment

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

yep you're right! I ran this twice and I don't get duplicate records because of the objectID field. What it does is replace all other fields in the object aside from the ID (which in our case will be the subject+code)

but hmmm that's a good point 🤔 wiping it clear and then populating might be good, and switching to replaceAllObjects seems easy enough
but then it worried me about anything going wrong with the API (e.g. running the script with 202401 currently will return 0 courses to be added since API is not working, so it would simply wipe the index instead of not touching it at all). What do you think?

.github/workflows/update-algolia.yaml Outdated Show resolved Hide resolved
functions/scripts/update-algolia-index.ts Outdated Show resolved Hide resolved
Copy link
Member

@aomi aomi left a comment

Choose a reason for hiding this comment

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

Also, you'll want to set up synonyms for stuff like ELEC == ECE and "computer science" == csc etc., (people do search sometimes spelling the entire subject 🤷 )

Comment on lines +61 to +62
subject: course.subject,
code: course.code,
Copy link
Member

Choose a reason for hiding this comment

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

Having a field that's just the concatenation like objectID helps with cases where people enter CSC100 without a space.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is objectID not taken into consideration for the search?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and re: synonyms for courses, are you thinking a sort of look up table with pre defined synonyms for the most common stuff?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature: Populate search index (Algolia) via a GitHub Action
2 participants