[ic] swish search - quotes

Dan Bergan dan at berganconsulting.com
Thu Feb 8 11:06:15 EST 2007

Quoting Peter <peter at pajamian.dhs.org>:

> On 02/07/2007 01:06 PM, Dan Bergan wrote:
>> However it looks like I will have to do some hacking in Swish.pm it
>> looks like quotes are always removed as "unsafe charachers":
>> $spec =~ s/[^-\w()"\s\*]+//g
>>     and $CGI::values{debug}
>>     and ::logError("Removed unsafe characters from search string");
>> (My regex skills may be a bit rusty, so please correct me if I'm reading
>> either of these wrong!)
>> Does this seem like a reasonable thing for me to do in Swish.pm:
>> #removed quote char (") from regex
>> $spec =~ s/[^-\w()\s\*]+//g
>>     and $CGI::values{debug}
>>     and ::logError("Removed unsafe characters from search string");
> You got it backwards, the ^ negates the character set, so it's removing
> characters that *don't* match anything in the set.  " is explicitly allowed.
> Peter

Thanks, Peter!  I guess my regex skills were a bit rusty!

To allow phrase searching I added the following line:
$spec =~ s/"/\\"/g;

Now, if someone searches for "word1 word2" (with the quotes included  
in the search box), it will return only those results where that exact  
phrase appears in the page.

Thanks for everyones help!

More information about the interchange-users mailing list