var pageLimit = 20; function secondStepSearch(caller) { var fullSearchRequest = { operation: 'fullSearch', tmId: currentTmId, limit: pageLimit, offset: $('#current-offset').val(), pattern:caller.innerHTML } $.ajax({ url: '/cat/concordia_gate.php', type: 'post', dataType: 'json', success: function (data) { presentFullSearchResults(data); }, data: fullSearchRequest }); } function presentFullSearchResults(data) { var pattern = $('#current-pattern').val(); var offset = parseInt($('#current-offset').val()); var begin = offset+1; var end = offset + pageLimit; var totalCount = parseInt(data['result']['totalCount']); if (end > totalCount) { end = totalCount; } var result = 'Showing results '+begin+' - '+end+' of '+totalCount+'
'; for (j=0;jYour phrase was not found. Try selecting another phrase: ').fadeOut(200).fadeIn(200); clearTextSelections(); } }, data: concordiaRequest }); } function renderResult(data) { $('#occurences').html(''); var res = ''; var disablePhraseSearch = true; if (typeof(data['result']['bestOverlayScore']) === 'undefined') { // ignore } else { var score = data['result']['bestOverlayScore']*100; res += '
Concordia score: '+score.toFixed(0)+'%
'; } if (typeof disablePhraseSearch !== 'undefined') { // ignore } else { res += '
Phrase search mode: enter phrase search mode
'; } var inputSentence = $('#search-input').val(); var markedSentence = ''; var fragments = ''; lastInsertedEnd = 0; for(var i = 0; i < data['result']['bestOverlay'].length; i++) { var fragment = data['result']['bestOverlay'][i]; //previous unmarked fragment markedSentence += htmlEncode(inputSentence.slice(lastInsertedEnd, fragment['matchedPatternStart'])); //the marked fragment var textFragment = htmlEncode(inputSentence.slice(fragment['matchedPatternStart'], fragment['matchedPatternEnd'])); markedSentence += ''+textFragment+''; lastInsertedEnd = fragment['matchedPatternEnd']; fragments += renderFragment(fragment, i); } //remaining unmarked fragment markedSentence += htmlEncode(inputSentence.slice(lastInsertedEnd)); res += '
'+markedSentence+'
'; res += '


'+fragments; return res; } function htmlEncode(value){ // Create a in-memory div, set its inner text (which jQuery automatically encodes) // Then grab the encoded contents back out. The div never exists on the page. return $('
').text(value).html(); } function renderFragment(fragment, number) { var result = '