From: Will Budicm Date: Thu, 24 Dec 2020 18:06:27 +0000 (+1100) Subject: Updated autocomplete to hash. X-Git-Url: https://lifelog.hopto.org/gitweb/?a=commitdiff_plain;h=d3eb97c7fcbdbc79e69a9440f8bb079c4f923bbd;p=LifeLog.git Updated autocomplete to hash. --- diff --git a/htdocs/cgi-bin/main.cgi b/htdocs/cgi-bin/main.cgi index 9e8eed5..9437a7f 100755 --- a/htdocs/cgi-bin/main.cgi +++ b/htdocs/cgi-bin/main.cgi @@ -970,8 +970,7 @@ $log_output .= qq(
View Statistics
-
Configure Log

+my $tail = q(
View Statistics  Configure Log

LOGOUT
); if($isPUBViewMode){$sideMenu=$frm=$srh=$tail=""}else{ $sideMenu = qq( @@ -1304,51 +1303,33 @@ sub authenticate { } sub fetchAutocomplete { + my $st = traceDBExe('SELECT LOG from LOG' . $stmE ); + my $awl = Settings::autoWordLength(); + my %hsh = (); while ( my @row = $st->fetchrow_array() ) { my ($wl,$log) = ("",$row[0]); - #Decode escaped \\n $log =~ s/\\n/\n/gs; $log =~ s/''/'/g; - - #Replace link to empty string - my @words = split( /($re_a_tag)/si, $log ); - foreach my $ch_i (@words) { - next if $ch_i =~ /$re_a_tag/; - next if index( $ch_i, " -1; - $ch_i =~ s/https//gsi; - $ch_i =~ s/($RE{URI}{HTTP})//gsi; - } - $log = join( ' ', @words ); - @words = split( ' ', $log ); + my @words = split( /\s/, $log ); foreach my $word (@words) { - #remove all non alphanumerics $word =~ s/[^a-zA-Z]//gs; $wl = length($word); - if ( $wl > 2 && $wl < Settings::autoWordLength()) { + if ( $wl > 2 && $wl < $awl) { $word = lc $word; - #parse for already placed words, instead of using an hash. - my $idx = index( $autowords, $word, 0 ); - if ( $idx > 0 ) { - my $end = index( $autowords, '"', $idx ); - my $existing = - substr( $autowords, $idx, $end - $idx ); - next if $word eq $existing; - } - - $autowords .= qq(,"$word"); + if(!$hsh{$word}){ $hsh{$word}=$word;$autowords .= qq(,"$word");} else{ next; } if ( $aw_cnt++ > &Settings::autoWordLimit ) { last; } } } - if ( $aw_cnt > Settings::autoWordLimit() ) { last; } } + undef %hsh; } sub cam {