From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 1F2CF138334 for ; Thu, 19 Dec 2019 21:02:52 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 7CD56E0954; Thu, 19 Dec 2019 21:02:49 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 5EF12E0948 for ; Thu, 19 Dec 2019 21:02:49 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 7964034DA40 for ; Thu, 19 Dec 2019 21:02:48 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id B109A990 for ; Thu, 19 Dec 2019 21:02:44 +0000 (UTC) From: "Göktürk Yüksek" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Göktürk Yüksek" Message-ID: <1576789087.173273b10e50d649924f70223cd5817585fc59af.gokturk@gentoo> Subject: [gentoo-commits] proj/devmanual:master commit in: / X-VCS-Repository: proj/devmanual X-VCS-Files: search.js X-VCS-Directories: / X-VCS-Committer: gokturk X-VCS-Committer-Name: Göktürk Yüksek X-VCS-Revision: 173273b10e50d649924f70223cd5817585fc59af X-VCS-Branch: master Date: Thu, 19 Dec 2019 21:02:44 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: cb67e0ed-12b8-4d7b-91ef-f672b69db014 X-Archives-Hash: f3eacf1834e6939d260a5fd7a25c4338 commit: 173273b10e50d649924f70223cd5817585fc59af Author: Göktürk Yüksek gentoo org> AuthorDate: Tue Dec 10 02:11:15 2019 +0000 Commit: Göktürk Yüksek gentoo org> CommitDate: Thu Dec 19 20:58:07 2019 +0000 URL: https://gitweb.gentoo.org/proj/devmanual.git/commit/?id=173273b1 search.js: highlight the search terms in results Signed-off-by: Göktürk Yüksek gentoo.org> search.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/search.js b/search.js index ab28f87..9cbf05a 100644 --- a/search.js +++ b/search.js @@ -42,9 +42,32 @@ function search() { $.each(results, function(index, result) { var uid = result.ref; var contents = getContents(documents, uid); + var stems = Object.keys(result.matchData.metadata); + var positions = []; + var text = ""; + var pos = 0; + + stems.forEach(function (stem) { + positions = positions.concat(result.matchData.metadata[stem].text.position); + }); + positions.sort(function(x, y) { + if (x[0] < y[0]) { return -1; } + else if (x[0] > y[0]) { return 1; } + else { return 0; } + }); + + for (var i = 0; i < positions.length; i++) { + text += contents.text.substring(pos, positions[i][0]); + pos = positions[i][0]; + text += ""; + text += contents.text.substring(pos, pos + positions[i][1]); + pos += positions[i][1]; + text += ""; + } + text += contents.text.substring(pos); $("#searchResults .modal-body").append(``); + ${contents.name}

${text}

`); }); } else { $("#searchResults .modal-body").empty();