[Lxr-dev] Solution for "Don't require glimpse for file search"
Brought to you by:
ajlittoz
From: Shree K. <sh...@pr...> - 2002-02-12 06:27:09
|
This is in response to the feature request "Don't require glimpse for file search" As was indicated in the request, there is no need to use glimpse as all the filename are present in the database... The idea is to get the list of all files in a particular release and filter the list using the regular expression specified by the user. First, we have to have a "getallfiles" method in MySQL.pm ------------------------------------------------------------------------------- Add the following to the "new" method: $self->{all_files_select} = $self->{dbh}->prepare ("select distinct f.filename ". "from symbols s, indexes i, files f, releases r ". "where s.symid = i.symid and i.fileid = f.fileid ". "and r.release = ?"); And add the new function: sub getallfiles { my ($self,$release) = @_; my ($rows, @ret); $rows = $self->{all_files_select}->execute($release); while ($rows-- > 0) { push(@ret, $self->{all_files_select}->fetchrow_array); } $self->{all_files_select}->finish(); return @ret; } ------------------------------------------------------------------------------- Now apply the following patch to "find": ------------------------------------------------------------------------------- < unless (open(FILELLISTING,$config->glimpsedir."/.glimpse_filenames")) { < &warning("Could not open .glimpse_filenames."); < return; < } < print("<hr>\n"); < $sourceroot = $config->sourceroot; < while($file = <FILELLISTING>) { < $file =~ s/^$sourceroot//; < if($file =~ /$searchtext/) { < print(&fileref("$file", "find-file", "/$file"),"<br>\n"); < } < } --- > # Modification to do file search without glimpse > my @files = $index->getallfiles($release); > my $file; > my $refs=''; > my $count=0; > while ($file = shift(@files)) { > if($file =~ /$searchtext/i) { > $refs .= &fileref("$file", "find-file", "/$file")."<br>\n"; > $count++; > } > } > print "<hr>\n"; > if ($count) { > print "Found $count files/directories matching <b>$searchtext</b><br>\n<hr>\n"; > print $refs; > } else { > print "No files/directories match <b>$searchtext</b><br>\n"; > } -------------------------------------------------------------------------------- The reason I use Perl for matching regexps is that this facility is not available in all sorts of databases - and even if it were, would the regular expression format be consistent ? |