Sorting by character length

This is the full code without the order.

import wixData from ‘wix-data’ ;
$w . onReady ( function () {
//TODO: write your page related code here…
});
let debounceTimer ;
export function searchBar_keyPress ( event ) {
$w ( “#loadingGif” ). show ();

**if**  ( debounceTimer ) { 
    clearTimeout ( debounceTimer ); 
    debounceTimer  =  **undefined** ; 
} 
debounceTimer  =  setTimeout (() => { 
    $w ( "#dataset1" ). setFilter ( wixData . filter () 
    . contains ( "title" ,  $w ( '#searchBar' ). value ) 
    
            ) 

        . then (() => { 
            count (); 
        }) 
},  200 ); 

}

function count () {
let total = $w ( ‘#dataset1’ ). getTotalCount ();
if ( total > 1 ) {
$w ( ‘#textResults’ ). text = ${ total } results were found. ;
$w ( “#loadingGif” ). hide ();
$w ( ‘#textResults’ ). show ();
}
if ( total === 1 ) {
$w ( ‘#textResults’ ). text = ${ total } result was found. ;
$w ( “#loadingGif” ). hide ();
$w ( ‘#textResults’ ). show ();
}
if ( total === 0 ) {
$w ( ‘#textResults’ ). text = “No result found!” ;
$w ( “#loadingGif” ). hide ();
$w ( ‘#textResults’ ). show ();
}
}


what I am doing is basically a dictionary.
I have a list of words and users can input the word in the searchbox and the repeaters that contain the words are filtered out.

The problem is that if a user wants to search for “z” he has to scroll down.
But if I order by:
1) character length
2) alphabetical order

Than the issue would be resolved satisfactorily.

Thanks :slight_smile: