Skip to content

add: searchBySutta and TDD && suttaNumOnly Array#653

Open
DylanAustin-TheDreamer wants to merge 3 commits into
buddhist-uni:mainfrom
DylanAustin-TheDreamer:dylan-sutta-search
Open

add: searchBySutta and TDD && suttaNumOnly Array#653
DylanAustin-TheDreamer wants to merge 3 commits into
buddhist-uni:mainfrom
DylanAustin-TheDreamer:dylan-sutta-search

Conversation

@DylanAustin-TheDreamer

Copy link
Copy Markdown
Contributor

Added functionality for searching nikaya references indefinitely.

We have 2 functions and a new array. StoreSuttaNumsOnly which stores objects in an array called suttaNumOnly.
Then we detect whether or not the user has input a number, then run searchBySuttaNum function. Just like how we handled joinsuttatitles but for nikaya indexes only this time.

This may have implications for other types of content with numbers. Maybe you can review this and help me understand how to make this feature better.

Although I have realized, a lot of our content titles use words for numbers - like one, six, twenty. if this is consistent, then this method might be perfectly fine.

@netlify

netlify Bot commented Jul 4, 2026

Copy link
Copy Markdown

Deploy Preview for obu ready!

Name Link
🔨 Latest commit 4cb92ee
🔍 Latest deploy log https://app.netlify.com/projects/obu/deploys/6a4fb16aed0def0008509986
😎 Deploy Preview https://deploy-preview-653--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.

Comment thread assets/js/search_index.js Outdated

joinedTitles = normalizeSuttaTitles(store);
suttaNumOnly = storeSuttaNumsOnly(store);
console.log(suttaNumOnly);

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.

Please remove debugging statements before putting up PRs :)

Comment thread assets/js/search_functions.js Outdated
if (!item || item.type !== "content" || item.category !== "canon") continue;
const title = item.title || "";
const titleJoin = title.normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/^\s*(?:DN|MN|SN|AN|KN|LAL|DA|MA|SA|EA|SNP|DHP|ITI|THAG|THIG|UD|NIDD|CV|BV|AP|JA|PV|VV|KP|PTS)\s*\d+(?:\.\d+)?\s*[:.-]?\s*/i, "").replace(/\s*[:\-–]\s*.*$/, "").toLowerCase().replace(/[^a-z0-9]/g, "");
const titleJoin = title.normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/^\s*(?:DN|MN|SN|AN|KN|LAL|DA|MA|SA|EA|SNP|DHP|ITI|THAG|THIG|UD|NIDD|CV|BV|AP|JA|PV|VV|KP|PTS|KHP|MV|T|MVU|VB|THAAP|SF)\s*\d+(?:\.\d+)?\s*[:.-]?\s*/i, "").replace(/\s*[:\-–]\s*.*$/, "").toLowerCase().replace(/[^a-z0-9]/g, "");

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.

THAAP was a typo in the title at https://buddhistuniversity.net/content/canon/tha-ap392+cmy

I'll correct that to "Tha-Ap"

Comment thread assets/js/search_functions.js Outdated
const item = obj[i];
if (!item || item.type !== "content" || item.category !== "canon") continue;
const title = item.title || "";
const titleJoin = title.replace(

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.

Why did you indent this line?

Comment thread assets/js/search_functions.js Outdated

function searchBySuttaNum (query, suttaNumOnly) {
var tokenResults = [];
const normalizedQuery = query.normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[^a-z0-9]/g, "").replace(/\./g, "").replace(/\s+/g, "").replace(" ", "").toLowerCase();

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.

Is all this normalizing necessary? What specific user queries are you trying to handle with this logic? Can you think of any queries for which this logic will do the wrong thing?

Comment thread assets/js/search_functions.js Outdated
var tokenResults = [];
const normalizedQuery = query.normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[^a-z0-9]/g, "").replace(/\./g, "").replace(/\s+/g, "").replace(" ", "").toLowerCase();
for (var i in suttaNumOnly){
const item = suttaNumOnly[i]

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.

missing the semicolon on the end

Comment thread assets/js/search_functions.js Outdated
}
finalResults = results.length ? results : findOneWordSuttaTitleMatches(data.q.trim(), joinedTitles);

let hasNumber = /\d/.test(data.q.trim());

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 trim a \d test

Comment thread assets/js/search_functions.js Outdated

let hasNumber = /\d/.test(data.q.trim());

if(hasNumber){

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.

Can you think of any queries where this will do the wrong thing?

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.

2 participants