Unfortunately (but perhaps unsurprisingly) Index Server does not fully cover the search criteria I wish to use. The use of wildcard searches is required, in any format (*stuff, st*ff, and stuff*). I've written a 'brute force' search program that matches on regular expressions, but with over 6000 documents to search it takes a while.
My question is this: does anybody have any ideas on how to improve the speed? My code for the search is
# Take each word from the array of search words and apply the qr// ope +rator to prevent a recompile for each regex. # Output the words to a new array using map (faster than foreach). @search_array = map { qr/\b$_\b/i } @and_array; # For each file within the directory while ( defined( $File = readdir(DIR) ) ) { # Skip the directory and parent directory (read as . and ..) next if $File =~ /^\.\.?$/; # Open the file for regular expression match open ( FILE, "$File" ) || die "Cannot open file $File: $!"; # Read file into an array @file_contents = (); @file_contents = <FILE>; close FILE; $nomatch = "0"; # Loop to match each search word held in the array against each line i +n the file. WORD: for $word ( @search_array ) { @found = (); @found = grep /$word/i, @file_contents; if ( scalar @found == 0 ) { $nomatch = "1"; last WORD; } } if ( $nomatch == "0" ) { $x = $x + 1; print LIST "$x $File ".$TelonDir.$in{'scope'}."\\$File \n"; } # End of while defined $File closedir DIR; close LIST;
Please go easy on me - I've learn't Perl from scratch by myself over the last 8 months and I'm certainly not the most adept!
elbow
Edit by dws to clean up tags
In reply to Speed up the search by elbow
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |