add: searchBySutta and TDD && suttaNumOnly Array#653
add: searchBySutta and TDD && suttaNumOnly Array#653DylanAustin-TheDreamer wants to merge 3 commits into
Conversation
✅ Deploy Preview for obu ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
…hist-uni.github.io into dylan-sutta-search
|
|
||
| joinedTitles = normalizeSuttaTitles(store); | ||
| suttaNumOnly = storeSuttaNumsOnly(store); | ||
| console.log(suttaNumOnly); |
There was a problem hiding this comment.
Please remove debugging statements before putting up PRs :)
| 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, ""); |
There was a problem hiding this comment.
THAAP was a typo in the title at https://buddhistuniversity.net/content/canon/tha-ap392+cmy
I'll correct that to "Tha-Ap"
| const item = obj[i]; | ||
| if (!item || item.type !== "content" || item.category !== "canon") continue; | ||
| const title = item.title || ""; | ||
| const titleJoin = title.replace( |
There was a problem hiding this comment.
Why did you indent this line?
|
|
||
| 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(); |
There was a problem hiding this comment.
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?
| 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] |
There was a problem hiding this comment.
missing the semicolon on the end
| } | ||
| finalResults = results.length ? results : findOneWordSuttaTitleMatches(data.q.trim(), joinedTitles); | ||
|
|
||
| let hasNumber = /\d/.test(data.q.trim()); |
There was a problem hiding this comment.
There's no need to trim a \d test
|
|
||
| let hasNumber = /\d/.test(data.q.trim()); | ||
|
|
||
| if(hasNumber){ |
There was a problem hiding this comment.
Can you think of any queries where this will do the wrong thing?
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.