File tree Expand file tree Collapse file tree 1 file changed +11
-12
lines changed Expand file tree Collapse file tree 1 file changed +11
-12
lines changed Original file line number Diff line number Diff line change @@ -56,28 +56,27 @@ <h1 class="text-4xl font-bold tracking-tight text-gray-900">
5656
5757 searchInput . addEventListener ( "input" , ( e ) => {
5858 const query = e . target . value . toLowerCase ( ) . trim ( ) ;
59- const results = [ ] ;
59+ let titleMatches = [ ] ;
60+ let descriptionMatches = [ ] ;
6061
6162 if ( query ) {
6263 allSoftwares . forEach ( category => {
6364 category . services . forEach ( service => {
64- if (
65- service . title . toLowerCase ( ) . includes ( query ) ||
66- service . description . toLowerCase ( ) . includes ( query )
67- ) {
68- const alreadyExists = results . find (
69- ( result ) => result . id === service . id
70- ) ;
65+ const titleMatch = service . title . toLowerCase ( ) . includes ( query ) ;
66+ const descriptionMatch = service . description . toLowerCase ( ) . includes ( query ) ;
7167
72- if ( ! alreadyExists ) {
73- results . push ( service ) ;
74- }
68+ if ( titleMatch ) {
69+ titleMatches . push ( service ) ;
70+ } else if ( descriptionMatch ) {
71+ descriptionMatches . push ( service ) ;
7572 }
7673 } ) ;
7774 } ) ;
7875 }
7976
80- renderResults ( results ) ;
77+ const sortedResults = [ ...titleMatches , ...descriptionMatches ] . slice ( 0 , 10 ) ;
78+
79+ renderResults ( sortedResults ) ;
8180 } ) ;
8281
8382 const renderResults = ( results ) => {
You can’t perform that action at this time.
0 commit comments