Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d0ec6da
Add: oneword token search based on the search patter we use
DylanAustin-TheDreamer Mar 24, 2026
4f966ff
removed: line reference comments
DylanAustin-TheDreamer Mar 24, 2026
8643466
add: sutta finder variable at the top for one word query
DylanAustin-TheDreamer Mar 24, 2026
5d5d6c8
Merge branch 'main' of https://github.com/DylanAustin-TheDreamer/budd…
DylanAustin-TheDreamer Mar 25, 2026
d86b787
Merge branch 'main' of https://github.com/DylanAustin-TheDreamer/budd…
DylanAustin-TheDreamer Apr 3, 2026
1860aa4
create: onewordtoken function and TDD - first failed now passes
DylanAustin-TheDreamer Apr 3, 2026
76b34f9
Merge branch 'main' of https://github.com/DylanAustin-TheDreamer/budd…
DylanAustin-TheDreamer Apr 6, 2026
26eff64
trying to get item titles from results array of objects
DylanAustin-TheDreamer Apr 10, 2026
fd5e9db
Merge branch 'main' of https://github.com/DylanAustin-TheDreamer/budd…
DylanAustin-TheDreamer Apr 11, 2026
e799cbc
add: fallback for oneword search results back to results on no results
DylanAustin-TheDreamer Apr 11, 2026
c6f4827
add: findoneword function in completed form with TDD
DylanAustin-TheDreamer Apr 11, 2026
c0649bc
add: new normalizetitle function and better results handling
DylanAustin-TheDreamer Apr 12, 2026
703e8c9
update: findoneword...() with matching against joinedTitles made from…
DylanAustin-TheDreamer Apr 13, 2026
2c16c89
Merge branch 'main' of https://github.com/DylanAustin-TheDreamer/budd…
DylanAustin-TheDreamer Apr 13, 2026
c0be5b6
Merge branches 'dylan-search-function' and 'main' of https://github.c…
DylanAustin-TheDreamer Apr 14, 2026
2905284
add: new test cases to normalizeSuttaTitles
DylanAustin-TheDreamer Apr 16, 2026
55cb72e
Merge branch 'main' of https://github.com/DylanAustin-TheDreamer/budd…
DylanAustin-TheDreamer Apr 16, 2026
24d19d6
add: remove the from beginning, better nikaya index handling and upda…
DylanAustin-TheDreamer Apr 16, 2026
77e02b5
Merge branch 'main' of https://github.com/DylanAustin-TheDreamer/budd…
DylanAustin-TheDreamer Apr 19, 2026
549d6c4
Merge branch 'main' of https://github.com/DylanAustin-TheDreamer/budd…
DylanAustin-TheDreamer Apr 23, 2026
a50ba3c
add: several test cases to match cases suggested on PR review, to sho…
DylanAustin-TheDreamer Apr 23, 2026
8a653f6
Merge branch 'main' of https://github.com/DylanAustin-TheDreamer/budd…
DylanAustin-TheDreamer Apr 25, 2026
332e7e5
Add: extra test cases and new normalizeSuttaTitles() handling
DylanAustin-TheDreamer Apr 25, 2026
d9b6d97
remove: un-used tokenResults variable
DylanAustin-TheDreamer Apr 25, 2026
8907d60
Merge branch 'main' of https://github.com/DylanAustin-TheDreamer/budd…
DylanAustin-TheDreamer Apr 27, 2026
49dd5cd
update: test case names to match test cases properly
DylanAustin-TheDreamer Apr 27, 2026
cf14f49
Merge branch 'main' of https://github.com/DylanAustin-TheDreamer/budd…
DylanAustin-TheDreamer Apr 27, 2026
a2d8a89
update: test case description for testing parse lal sutra
DylanAustin-TheDreamer Apr 27, 2026
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update: findoneword...() with matching against joinedTitles made from…
… store items with new normalized titles
  • Loading branch information
DylanAustin-TheDreamer committed Apr 13, 2026
commit 703e8c91c3cb1d8598a6d77f4f9986ea47dd7d7e
41 changes: 24 additions & 17 deletions assets/js/search_functions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
// Parameters
var BMAX = 250; // Max blurb size in characters
var RMAX = 100; // Max number of results to display
var joinedTitles = []

function normalizeSuttaTitles (obj) {
var joinedTitleDatabase = []

for (var i in obj){
const item = obj[i];
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|SNP|DHP|ITI|THAG|THIG|UD)\s*\d+(?:\.\d+)?\s*[:.-]?\s*/i, "").replace(/(\bsutta\b).*$/i, "$1").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.

So right now, there are some bugs with this function, for a quick sampling:

  • ma220 is right now returning ma220aritthasutrathediscourseonknowingthebetterwaytocatchasnake when it should be aritthasutra
  • ma128 is giving ma128upasakasutradiscourseonthewhitecladdisciple instead of upasakasutra
  • thequestionsofkingmalindaanabridgementofthemilindapanha should probably be skipped
  • themahasatipatthanasutta and theuppatipatikasutta and theyogasutra shouldn't include the the at the beginning
  • The Thig / Thag entries are not working right. For example: subhajivakambavanikatherigathasubhaofjivakasmangogrove or punnatherigathapunnika
  • for ma80, we should just filter it out instead of giving ma80theroughcloth
  • lal26 has lal26dharmacakrapravartanasutrathediscoursethatsetthedharmawheelrolling instead of dharmacakrapravartanasutra

Add tests for these cases and fix the implementation so that these cases pass. In our call tomorrow morning, I can show you how I found these.

joinedTitleDatabase.push({
ref: i,
title: titleJoin,
matchData: { metadata: {} }
});
}
return joinedTitleDatabase;
}

function getPositions(result, field) {
var positions = [];
Expand Down Expand Up @@ -169,22 +187,14 @@ function displaySearchResults(results) {
}
}

function normalizeSuttaTitles (query) {
const titleMatch = query.normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/^\s*(?:DN|MN|SN|AN|SNP|DHP|ITI|THAG|THIG|UD)\s*\d+(?:\.\d+)?\s*[:.-]?\s*/i, "").replace(/(\bsutta\b).*$/i, "$1").toLowerCase().replace(/[^a-z0-9]/g, "");
return titleMatch;
}

function findOneWordSuttaTitleMatches(query, store) {
function findOneWordSuttaTitleMatches(query, joinedTitles) {
var tokenResults = [];
const normalizedQuery = query.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/[^a-z0-9]/g, "");
for (var i in store){
const item = store[i];
if (!item || item.type !== "content" || item.category !== "canon") continue;
const title = (item && item.title) ? item.title : "";
const titleMatch = normalizeSuttaTitles(title);
if(titleMatch === normalizedQuery){
for (var i in joinedTitles){
const item = joinedTitles[i]
if(item.title === normalizedQuery){
tokenResults.push({
ref: i,
ref: item.ref,
score: 1,
matchData: { metadata: {} }
});
Expand All @@ -199,9 +209,6 @@ function handleSearchMessage(data, searchFn) {
var warning = "";
var words = data.q.trim().split(" ");

if(words.length === 1){
tokenResults = findOneWordSuttaTitleMatches(data.q.trim(), store)
}
for (var i = 0; i < words.length; i++) {
const s = words[i].trim();
if (!s.startsWith("+") && !s.startsWith("-") && s.length > 1 && lunr.stopWordFilter(s)) {
Expand Down Expand Up @@ -242,7 +249,7 @@ function handleSearchMessage(data, searchFn) {
});
});
}
finalResults = results.length ? results : tokenResults = findOneWordSuttaTitleMatches(data.q.trim(), store);
finalResults = results.length ? results : tokenResults = findOneWordSuttaTitleMatches(data.q.trim(), joinedTitles);
Comment thread
khemarato marked this conversation as resolved.
Outdated
return {
"warninghtml": warning,
"html": displaySearchResults(finalResults),
Expand Down
2 changes: 2 additions & 0 deletions assets/js/search_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ var idx = lunr(function () {
}
});

joinedTitles = normalizeSuttaTitles(store);
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.

Oh yeah. That's what I meant! You got it 🙂


self.onmessage = function(e) {
self.postMessage(handleSearchMessage(e.data, idx.search.bind(idx)));
}
21 changes: 14 additions & 7 deletions assets/js/tests/search-worker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,22 +300,29 @@ describe('getBlurbForResult', () => {

// ── normalizeSuttaTitles ─────────────────────────────────────────────
describe('normalizeSuttaTitles', () => {
it('takes a sutta title from database store and parses all unique characters to match user query, + joins words', () => {
const mockTitle = 'MN 35 Cūḷa Saccaka Sutta: The Shorter Discourse With Saccaka'
const result = normalizeSuttaTitles(mockTitle);
assert.equal(result, 'culasaccakasutta');
})
it('returns an array of database objects with a new normalized title', () => {
const mockStore = {
id1: {
title: 'MN 35 Cūḷa Saccaka Sutta: The Shorter Discourse With Saccaka',
type: 'content',
category: 'canon'
}
};
const result = normalizeSuttaTitles(mockStore);
assert.equal(result.length, 1);
assert.equal(result[0].ref, 'id1');
assert.equal(result[0].title, 'culasaccakasutta');
});
});

// ── findOneWordSuttaTitleMatches ─────────────────────────────────────────────
describe('findOneWordSuttaTitleMatches', () => {
it('returns matched item when query matches title exactly', () => {
const mockStore = {
'id1': { title: 'MN 35 Cūḷa Saccaka Sutta: The Shorter Discourse With Saccaka', type: 'content', category: 'canon' }
'id1': { title: 'culasaccakasutta', type: 'content', category: 'canon' }
};
const result = findOneWordSuttaTitleMatches('culasaccakasutta', mockStore);
assert.equal(toLocal(result).length, 1);
assert.equal(toLocal(result)[0].ref, 'id1');
});
});

Expand Down