Skip to content

Dylan parse features#646

Closed
DylanAustin-TheDreamer wants to merge 19 commits intobuddhist-uni:mainfrom
DylanAustin-TheDreamer:dylan-parse-features
Closed

Dylan parse features#646
DylanAustin-TheDreamer wants to merge 19 commits intobuddhist-uni:mainfrom
DylanAustin-TheDreamer:dylan-parse-features

Conversation

@DylanAustin-TheDreamer
Copy link
Copy Markdown
Contributor

Here are some regex parsing edits to help clean user input - This is to match user input with our backend ruleset for querying the database items.

Result: ability to return more database items that match user input.

There is one particular regex that identifies the word sutta and puts a space before it in order to split it from the rest of the pali words. This can help when typing sutta names as all one word. Some sutta names seem to have only one pali name then sutta - this can help the search.

However, two pali names and sutta are harder to detect when written all in one word - So therefore, the edit to add with this is on branch dylan-search-function, where I implement the one word token search, that solves even more cases like this.

But highlights don't work with the one word query so this needs to be looked into further as well.

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 25, 2026

Deploy Preview for obu ready!

Name Link
🔨 Latest commit b7ed0a4
🔍 Latest deploy log https://app.netlify.com/projects/obu/deploys/69de212794213f0008991fda
😎 Deploy Preview https://deploy-preview-646--obu.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Collaborator

@khemarato khemarato left a comment

Choose a reason for hiding this comment

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

Good start. Let's learn some software engineering! 😺

Comment thread assets/js/search_functions.js Outdated
var warning = "";
var words = data.q.trim().split(" ");

// Dylan's edit - remove quotes? - line 178 - 187
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There's no need to plant your flag 😆

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hahaha - sowwy

Its the first thing I thought of to be clear about things but you're right. I'm just learning.

Can I ask though, how should I handle comments?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's just say, there's no need for you to add any comments? The test cases should document what your functions do.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah that makes sense - it keeps me very focused on the TDD part of the project as well then which is good.

Comment thread assets/js/search_functions.js Outdated
var words = data.q.trim().split(" ");

// Dylan's edit - remove quotes? - line 178 - 187
// /["']/g is a JavaScript regular expression literal - g = global flag (match all occurrences, not just the first)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You can assume readers know about regex strings.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

understood

Comment thread assets/js/search_functions.js Outdated

// Normalize leading nikaya index, e.g. "MN6" -> "MN 6"
// I wrote out some for loops and char checks but AI suggested regex when I had him check my code.
// Regex seems straight forward you just need to research it as I still need to. I would have preferred manually doing it so I can practice my ability
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Learning and practicing regex is a good skill too!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

understood - I'll make it a regular addition to my parsing work

Comment thread assets/js/search_functions.js Outdated
// /["']/g is a JavaScript regular expression literal - g = global flag (match all occurrences, not just the first)
var preWordsParse = data.q.replace(/["']/g, "");

// Normalize leading nikaya index, e.g. "MN6" -> "MN 6"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Make this its own function, normalizeSuttaRefs or something and start off by describing what you want that function to do in the tests file. Start off with a base case that searches without a ref should be returned unaltered. Run the tests and watch it fail. Then add an implementation that just returns the string that you passed in, rerun the test and watch it pass. This is called "test-driven development." Then slowly add more complicated test cases and getting your code to pass them, until you've eventually built up all the functionality you want.

Comment thread assets/js/search_functions.js Outdated
preWordsParse = preWordsParse.replace(/\b([\p{L}]+?)sutta\b/giu, "$1 sutta");

// check if preWordsParse has sutta using regex .text()
const hasSutta = /\bsutta\b/i.test(preWordsParse);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do the same here. Make hasSutta a function and add tests for it in the test file.

@khemarato khemarato closed this Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants