From 044c671da2ae43cda85f7664ad540ff8188e86dc Mon Sep 17 00:00:00 2001
From: annegf <anne.garciafernandez@univ-grenoble-alpes.fr>
Date: Tue, 4 Feb 2025 10:01:32 +0100
Subject: [PATCH] Order search result by asc book, asc n

---
 static/js/auto_app_minisearch.js | 98 ++++++++++++++++----------------
 1 file changed, 48 insertions(+), 50 deletions(-)

diff --git a/static/js/auto_app_minisearch.js b/static/js/auto_app_minisearch.js
index 8fb194c7..f9077401 100644
--- a/static/js/auto_app_minisearch.js
+++ b/static/js/auto_app_minisearch.js
@@ -11,85 +11,83 @@ storeFields: $showable_fields // fields to return with search results
 let $data_json = 'static/json/auto_index.json';
 
 const renderSearchResults = (results) => {
-$resultsList.innerHTML = results.map(({ book, chapter, n, lem,BnFfr4967, BnFfr5299, BnFfr23145, BnFfr49967, Cha514, BnFfr23146, BnFfr17274, Vat966,
+    //JSON.stringify(results);
+    //results = results.filter((result) => result.book == 1)//filter book 1
+    //results.sort((a,b) => a.n - b.n); //sort by n (only)
+    // sort by book, and then n (line number)
+    results.sort((a,b) => {
+      if (a.book < b.book) return -1;
+      if (a.book > b.book) return 1;
+      if (a.n < b.n) return -1;
+      if (a.n > b.n) return 1;
+      return 0;
+    });
+    $resultsList.innerHTML = results.map(({ book, chapter, n, lem,BnFfr4967, BnFfr5299, BnFfr23145, BnFfr49967, Cha514, BnFfr23146, BnFfr17274, Vat966,
 Aix419, BnFfr1724, Aix966 }) => {
-
-let $result=`<h5 xmlns="http://www.w3.org/1999/xhtml" class="mt-3">Vers <a href="/book${book}/${chapter}#${n}">${n}</a></h5><dl xmlns="http://www.w3.org/1999/xhtml">
+    let $result=`<h5 xmlns="http://www.w3.org/1999/xhtml" class="mt-3">Vers <a href="/book${book}/${chapter}#${n}">${n}</a></h5><dl xmlns="http://www.w3.org/1999/xhtml">
    <dt>Livre : </dt>
    <dd>${book}</dd>
    <dt>Chapitre : </dt>
    <dd>${chapter}</dd>
    <dt>Lemme :</dt>
    <dd>${lem}</dd>`
-   if (! (`${BnFfr4967}` === "undefined") ) {
-   $result += `
-   
+    if (! (`${BnFfr4967}` === "undefined") ) {
+      $result += `
    <dt>BnFfr4967 : </dt>
    <dd>${BnFfr4967}</dd>
-   `}
-   if (! (`${BnFfr5299}` === "undefined") ) {
-   $result += `
-   
+    `}
+    if (! (`${BnFfr5299}` === "undefined") ) {
+      $result += `
    <dt>BnFfr5299 : </dt>
    <dd>${BnFfr5299}</dd>
-   `}
-   if (! (`${BnFfr23145}` === "undefined") ) {
-   $result += `
-   
+    `}
+    if (! (`${BnFfr23145}` === "undefined") ) {
+      $result += `
    <dt>BnFfr23145 : </dt>
    <dd>${BnFfr23145}</dd>
-   `}
-   if (! (`${BnFfr49967}` === "undefined") ) {
-   $result += `
-   
+    `}
+    if (! (`${BnFfr49967}` === "undefined") ) {
+      $result += `
    <dt>BnFfr49967 : </dt>
    <dd>${BnFfr49967}</dd>
-   `}
-   if (! (`${Cha514}` === "undefined") ) {
-   $result += `
-   
+    `}
+    if (! (`${Cha514}` === "undefined") ) {
+      $result += `
    <dt>Cha514 : </dt>
    <dd>${Cha514}</dd>
-   `}
-   if (! (`${BnFfr23146}` === "undefined") ) {
-   $result += `
-   
+    `}
+    if (! (`${BnFfr23146}` === "undefined") ) {
+      $result += `
    <dt>BnFfr23146 : </dt>
    <dd>${BnFfr23146}</dd>
-   `}
-   if (! (`${BnFfr17274}` === "undefined") ) {
-   $result += `
-   
+    `}
+    if (! (`${BnFfr17274}` === "undefined") ) {
+      $result += `
    <dt>BnFfr17274 : </dt>
    <dd>${BnFfr17274}</dd>
-   `}
-   if (! (`${Vat966}` === "undefined") ) {
-   $result += `
-   
+    `}
+    if (! (`${Vat966}` === "undefined") ) {
+      $result += `
    <dt>Vat966 : </dt>
    <dd>${Vat966}</dd>
-   `}
-   if (! (`${Aix419}` === "undefined") ) {
-   $result += `
-   
+    `}
+    if (! (`${Aix419}` === "undefined") ) {
+      $result += `
    <dt>Aix419 : </dt>
    <dd>${Aix419}</dd>
-   `}
-   if (! (`${BnFfr1724}` === "undefined") ) {
-   $result += `
-   
+    `}
+    if (! (`${BnFfr1724}` === "undefined") ) {
+      $result += `
    <dt>BnFfr1724 : </dt>
    <dd>${BnFfr1724}</dd>
-   `}
-   if (! (`${Aix966}` === "undefined") ) {
-   $result += `
-   
+    `}
+    if (! (`${Aix966}` === "undefined") ) {
+      $result += `
    <dt>Aix966 : </dt>
    <dd>${Aix966}</dd>
-   `}
-   
-   $result += `</dl>`
-return $result
+    `}
+    $result += `</dl>`
+    return $result
 }).join('\n')
 
         if (results.length > 0) {
-- 
GitLab