// ============================ Database ============================ function queryDatabase() { var cVal if(sVal() == "") return // empty input if (liveDatabaseMode == true) calcLiveDatabase(userDBlive) // calculate gematria for live database for enabled ciphers $("#calcMain").addClass("splitInterface") // split screen if (document.getElementById("queryArea") == null) { // create div if it doesn't exist var o = '
' $(o).appendTo('body'); } mArr = [] // array with matching phrases from database gemArr = [] // gematria of current phrase for enabled ciphers gemArrCiph = [] // indices of enabled ciphers numericalMode = NumberArray() // boolean var num_index = 0 // numerical array for (i = 0; i < cipherList.length; i++) { if (cipherList[i].enabled) { if (!numericalMode) { val = cipherList[i].calcGematria(sVal()) // if (val == 0) val = "n/a" gemArr.push(val) // value for current phrase in each enabled cipher } else { // numerical mode if (num_index < pArr.length) { gemArr.push(pArr[num_index]); num_index++ } // assign first number to first enabled cipher else { gemArr.push('-') } // if more ciphers than numbers push zero } gemArrCiph.push(i) // corresponding cipher index } } // console.log(gemArr) // console.log(gemArrCiph) if (optFiltCrossCipherMatch) { searchDBcrossCipher() } else if (optFiltSameCipherMatch) { searchDBsameCipher() } queryResultInitial = [...queryResult] // save initial matches // console.log(queryResult) // var longestPhr = 0; var tmp // for (i = 0; i < queryResult.length; i++) { // tmp = queryResult[i][1].length // if (tmp > longestPhr) longestPhr = tmp // } // var tWidth = longestPhr*11 + 58*gemArrCiph.length // 2x1px outer borders + phrase cell and amount of ciphers var tWidth = 202 + 58*gemArrCiph.length // 2x1px outer borders + phrase cell and amount of ciphers $("#queryArea").css("min-width", tWidth) // set initial/minimal width for the table $("#queryArea").css("width", tWidth) // set initial/minimal width for the table /*var o = 'min-width:'+tWidth+';width:'+tWidth+';' $("#queryArea").attr("style", o) // set minimal/initial width for the table*/ updateDatabaseQueryTable(0, dbPageItems) } function clearDatabaseQueryTable() { $("#calcMain").removeClass("splitInterface") $("#queryArea").remove() // remove element from page searchBarValue = '' // clear search bar queryResult = [] // clear queryResultInitial = [] // clear } function searchDBcrossCipher() { // populate "queryResult" array with matching phrases var p, m, n queryResult = [] // reset matching phrases var tmpArr = [] // one phrase with score and gematria var tmpVal = 0 // current phrase value var gemArrCiphUsed = [...gemArrCiph] if (liveDatabaseMode == true) { // 0,1,2... len = gemArrCiph.length gemArrCiphUsed = [] for (n = 0; n < len; n++) { gemArrCiphUsed.push(n) } } // take phrase, take cipher, all values match in cipher add score, build string, next phrase, then sort by score for (p = 0; p < userDB.length; p++) { // for each phrase in database tmpArr = [0, userDB[p][0]] // reset, set score[0], phrase[1] for (m = 0; m < gemArrCiphUsed.length; m++) { // for each enabled cipher index tmpVal = Number(userDB[p][gemArrCiphUsed[m]+1]) // value for that phrase (+1 because [0] contains phrase), string to number tmpArr.push(tmpVal) // first add values irrelevant of match validity for (n = 0; n < gemArr.length; n++) { // for each gematria value (cross cipher) if (tmpVal == gemArr[m]) { // tmpArr[0] += gemArr[n] * 10 // add score for a matching value, same cipher tmpArr[0] += 10 + 0.00001*tmpVal // add score for a matching value, same cipher n = gemArr.length // exit innermost loop (score is added once for same cross cipher values) } else if (tmpVal == gemArr[n]) { // tmpArr[0] += gemArr[n] // cross cipher tmpArr[0] += 1 + 0.00001*tmpVal // cross cipher n = gemArr.length // exit innermost loop } } } if (tmpArr[0] > 0) queryResult.push(tmpArr) // if total score is more than zero, add phrase to array } queryResult.sort(function(a, b) { // sort by score (descending) return b[0] - a[0]; // sort based on index 0 values ("freq" is array of arrays), (b-a) descending order, (a-b) ascending }); } function searchDBsameCipher() { // populate "queryResult" array with matching phrases var p, m, n queryResult = [] // reset matching phrases var tmpArr = [] // one phrase with score and gematria var tmpVal = 0 // current phrase value var gemArrCiphUsed = [...gemArrCiph] if (liveDatabaseMode == true) { // 0,1,2... len = gemArrCiph.length gemArrCiphUsed = [] for (n = 0; n < len; n++) { gemArrCiphUsed.push(n) } } // take phrase, take cipher, all values match in cipher add score, build string, next phrase, then sort by score for (p = 0; p < userDB.length; p++) { // for each phrase in database tmpArr = [0, userDB[p][0]] // reset, set score[0], phrase[1] for (m = 0; m < gemArrCiphUsed.length; m++) { // for each enabled cipher index tmpVal = Number(userDB[p][gemArrCiphUsed[m]+1]) // value for that phrase (+1 because [0] contains phrase), string to number tmpArr.push(tmpVal) // first add values irrelevant of match validity if (tmpVal == gemArr[m]) { // tmpArr[0] += gemArr[m] // same cipher, add score tmpArr[0] += 1 + 0.00001*gemArr[m] // same cipher, add score } } if (tmpArr[0] > 0) queryResult.push(tmpArr) // if total score is more than zero, add phrase to array } queryResult.sort(function(a, b) { // sort by score (descending) return b[0] - a[0]; // sort based on index 0 values ("freq" is array of arrays), (b-a) descending order, (a-b) ascending }); } function searchBarDBQuery(str) { // search bar searchBarValue = str // save input if (str == "") { queryResult = [...queryResultInitial] // restore inital matches updateDatabaseQueryTable(0, dbPageItems) document.getElementById('querySearchInput').focus() return } var i; var tmpPhr = ''; var tmpPhr2 = ''; queryResult = [] // clear current matches for (i = 0; i < queryResultInitial.length; i++) { tmpPhr = queryResultInitial[i] if (encodingMenuOpened) { // encoding mode if (encodingMode == 0 && optGemSubstitutionMode) { // syllables, substitution mode tmpPhr2 = tmpPhr.replace(/\[.+\]/g, '').trim() // exclude comments when searching (anagram link) if (tmpPhr2.match(new RegExp(str)) !== null) { queryResult.push(tmpPhr) } } else if (tmpPhr.match(new RegExp(str)) !== null) { queryResult.push(tmpPhr) } } else { // database match if (tmpPhr[1].match(new RegExp(str)) !== null) queryResult.push(tmpPhr) } } updateDatabaseQueryTable(0, dbPageItems) } function updateDatabaseQueryTable(stPos = 0, dItems, scrollBarEvent = false) { // starting position, total displayed items var ms, x, y, mCross, mSame, curCiph, curCiphCol // stPos - starting position // dbPageItems - number of phrases in one section var nextBlock = stPos+dbPageItems // position for next section if (nextBlock > queryResult.length) nextBlock = queryResult.length // out of bounds var valPos = 2 // used to retrive gematria from "gemArr" (no recalculation, [0] - score, [1] - phrase) var firstPhrase = true // display cipher names before the first phrase var tmpComment, commentMatch, dispPhrase // temporary variables to display comments [...] $("#queryArea").removeClass("minimizeQuery") // unhide query area var curPos = stPos // current position begins with starting index var endPos = stPos + dItems // ending position if (curPos < 0) curPos = 0 // out of bounds if (!scrollBarEvent) { if (endPos > queryResult.length) endPos = queryResult.length sliderMax = Math.floor(queryResult.length/dbPageItems) if (queryResult.length % dbPageItems == 0) sliderMax -= 1 // if total is divisible, no pagination for last element curSliderPos = Math.round(curPos/dbPageItems) ms = 'Click to minimize' ms += '| '
ms += queryResult.length.toLocaleString('en')+' matches'
ms += ' ' ms += ' '
ms += ''
ms += ''
ms += ''
ms += ' '
ms += '-' ms += ' '+nextBlock ms += ' | '
for (z = 0; z < gemArrCiph.length; z++) { // use compact layout
curCiph = cipherList[ gemArrCiph[z] ]
curCiphCol = (optColoredCiphers) ? 'hsl('+curCiph.H+' '+curCiph.S+'% '+curCiph.L+'% / 1)' : ''
// ms += ''+curCiph.cipherName.replace(/ /g, " ")+' | ' // color of cipher displayed in the table
ms += '' ms += curCiph.cipherName+' | ' // color of cipher displayed in the table } ms += "
| ' + dispPhrase + ' | ' // phrase at index 1 valPos = 2 // reset position for new phrase for (y = 0; y < gemArrCiph.length; y++) { // gemArrCiph contains indices of ciphers used for query curCiph = cipherList[ gemArrCiph[y] ] curCiphCol = (optColoredCiphers) ? 'hsl('+curCiph.H+' '+curCiph.S+'% '+curCiph.L+'% / 1)' : '' if (liveDatabaseMode == true) { gemVal = (encodingMenuOpened) ? curCiph.calcGematria(queryResult[x]) : curCiph.calcGematria(queryResult[x][1]) // recalculate displayed value } else { gemVal = queryResult[x][valPos] // value only } // if (gemVal == 0) gemVal = "-" valPos++ // increment value position // mSame - same cipher match, mCross - cross cipher match if ( gemVal == gemArr[y] ) {mSame = true} else {mSame = false} // if value is at the same index (meaning same cipher) if (gemArr.indexOf(gemVal) > -1) {mCross = true} else {mCross = false} ms += '' // use instead of .tC to disable highlighting/blinking/hide effects on click if (mSame) { ms += ' '+gemVal+' | ' // number properties are available } ms += '