I'm building a search engine to use against my companies files. My first version was a straightforward use of Index Server with modifications to the asp script that came with it. My second version was a Perl CGI script that called the asp script to run Index Server and pass the details back to the Perl script. From there I could use Perl to manipulate the files as I wished (i.e. highlighting search words).

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.