Hi,
Well, I did it in the server side by modifying the query() function. Basically, I used the regexp function in the search function in DBMAN...if u want
to search for e.g. 2 words
- 'word a' AND 'word b' then the regexp is 'word a'/ && /'word b'
- 'word a' OR 'word b' then the regexp is 'word a'/ | | /'word b'
so, u need to modify the sub query function where it builds the regexp
# Now let's build up all the regexpressions we will use. This saves the
program
# from having to recompile the same regular expression every time.
foreach $field (@search_fields) {
my $tmpreg = "$in{$db_cols[$field]}";
# u can use a marker of whether u want AND or OR for ur multiple words
# e.g. u can use a SELECT field to show option to match ALL words, or match
ANY word
# in the HTML.PL under view_search
# <select>
# <option name=match_all value=1>Match All words
# <option name=match_all value=0> Match Any word
# this will allow the query function to generate the appropriate regexp for
the multi word search
$tmpreg=~s/\s+/ /g; # strip excess spaces
($in{'match_all'}) ? $tmpreg=~s/\s/\/i&&\//g) :
($tmpreg=~s/\s/\/i|\//g); # generate the regexp of AND and OR depending on
ur choice
}
}
($in{$db_cols[$field]} eq "*") and ($tmpreg = ".*"); # A "*" matches
anything.
# add /i after $tmpreg for case insensitive search
$regexp_func[$field] = eval "sub { m/$tmpreg/i }";
$regexp_bold[$field] = $tmpreg;
I'm a novice perl programmer and i guess this is quite a kludge, but at least the user doesn't need to know regex to do multiple word searches. The only thing that the user needs to do is make sure he separates each word with a space...but i guess one could use commas as delimiters too. The best would be to allow things like
'word a' AND 'word b' OR 'word c'...etc
i.e. english like statements..then to translate it into regex
Hope there's a more elegant solution though