in reply to CGI search script: Exclusion list

I don't want to read through all that code right now, but the basic idea for your stop-words is:
$serach = "any foo and bar not frob"; #your search-string open STOP, stopwords.txt; while (<STOP>) { chomp; $search=~/$_//g; } close STOP;
If your stoplist and/or searchstring are so large that this is too slow, ask again for faster solutions.

Replies are listed 'Best First'.
Re^2: CGI search script: Exclusion list
by graff (Chancellor) on Mar 26, 2006 at 02:07 UTC
    This really isn't very good advice. First, you have the procedure the wrong way around: normally, the stopword list is fairly short and is held in memory, while the "search-string" data can be really huge, and is processed a line at a time.

    But your regex substitution is actually kind of insidious. The deletion of stop words needs to be anchored to word boundaries. If the stop word list included "me or and a", your approach would reduce the word "memoranda" to just "m".

    In general, the best approach is: store the stop words as hash keys, read the input text and tokenize it into words (being careful to remove punctuation as well as whitespace), then for each word, if it exists as a hash key, skip it.