Gossamer Forum
Home : Products : DBMan : Customization :

Substituting special characters

Quote Reply
Substituting special characters
I have some records on my database that have special characters, like: "Cybercafé".

Is there a way to substitute special characters in the query string and in the database. something like this:
beggining of sub query:
in{'keyword'} =~ s/é/e/;

and later on sub query:

LINE: while (<DB> ) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
$line = $_;
chomp ($line);
$line =~ s/é/e/;
@values = &split_decode($line);
...

Like this if the user enter with "cybercafé" or "cibercafe", dbman will find the right record.

thanks.
Quote Reply
Re: Substituting special characters In reply to
That might work, but I have a concern. Your accented character won't print out in your results. The results as saved in the @hits array are based on the @values array. Whatever is in @values goes into @hits. So it would defeat the purpose of having the accented characters in the first place.


------------------
JPD





Quote Reply
Re: Substituting special characters In reply to
Hello JPDeni,

I really need your help on this one, it's very important for my site.

You said that @hits are made from @values, what if I created a copy of @values with the special characters, I one without, I could search on one, and pass the values to @hits with the other... This way I would have accented characters on the output.

Since I only have 1.500 records, and that wont grow much, I think the speed og the site wont be affected.

The problem is implementing that, you need to understand deeply how the sub query works.
Quote Reply
Re: Substituting special characters In reply to
Got it working, this is how I did it, if it anyone is interested:

sub query ()
...
if ($in{'keyword'}) {
$i = 0;
$in{'ma'} = "on";
foreach $column (@db_cols) {
...
$in{$column} =~ tr/áãâàéêèíîìóõôòúûùç/aaaaeeeiiioooouuuc/;
...
}
}
else {
$i = 0;
...
$in{$column} =~ tr/áãâàéêèíîìóõôòúûùç/aaaaeeeiiioooouuuc/;
}
}
...
LINE: while (<DB> ) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
$line = $_;
chomp ($line);
@values_com = &split_decode($line);
$line =~ tr/áãâàéêèíîìóõôòúûùç/aaaaeeeiiioooouuuc/;
@values = &split_decode($line);
...
if ($key_match &#0124; &#0124; (!($in{'keyword'}) && !($in{'ma'}))) {
if ($sb) {
$sortby{(($#hits+1) / ($#db_cols+1))} = $values_com[$sb];
push (@hits, @values_com);
}
else {
(($numhits >= $first) and ($numhits <= $last)) and push (@hits, @values_com);
}
$numhits++;
}

The only problem is the words with accented characters as the first letter of the word, like "árabe", I dont know why, but it doesnt work!
Quote Reply
Re: Substituting special characters In reply to
That's an excellent solution!

I'm not sure why it would be a problem with the first letters of the words. Unless they were capitalized. You may need to add the uppercase letters to your tr// line.

That's the only thing I can think of.


------------------
JPD





Quote Reply
Re: Substituting special characters In reply to
Hey, you are right... That solved my problem... Thanks a lot JPDeni.

Now I only have ONE problem left, I will open a new thread for it, no one found a solution for it when I mentioned before.

by the way, the code I sent had an error, where is the correction:

...
}
else {
$in{$column} =~ tr/áãâàéêèíîìóõôòúûùç/aaaaeeeiiioooouuuc/;
$i = 0;
...
}
}
...
Quote Reply
Re: Substituting special characters In reply to
Wonderful! Sometimes it just takes another person who isn't involved to see it.

I really like your solution to the problem. Very creative.


------------------
JPD