<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">var documentIndex = [];
var totalSection = 0;
function addIndex(section) {
    console.time("add index");
    let sectionData = $("#section_"+section+" .ctext");
    let indexLength = sectionData.length;
    console.log(indexLength);
    let sectionIdx = section-1;
    documentIndex[sectionIdx] = {};
    let origin;
    for(let idx=0; idx &lt; indexLength; idx++) {
        origin = sectionData[idx].getAttribute("origin");
        // console.log("origin is", origin);
        if (!documentIndex[sectionIdx][origin])
            documentIndex[sectionIdx][origin] = [];
        documentIndex[sectionIdx][origin].push(sectionData[idx]);
    }
    totalSection++;
    console.timeEnd("add index");
    console.log("document index", documentIndex);
}

function findMatch(word) {
    let matches = 0;
    for(let secIdx=0; secIdx &lt; totalSection; secIdx++) {
        if (documentIndex[secIdx][word])
            matches += documentIndex[secIdx][word].length;
    }
    return matches;
}

function findMatchEle(word) {
    console.log("word is", word);
  let elements = [];
  for (let secIdx = 0; secIdx &lt; totalSection; secIdx++) {
    if (documentIndex[secIdx][word])
      elements = elements.concat(documentIndex[secIdx][word]);
  }
  return elements;
}</pre></body></html>