Zen Cart Logo
Forums / General Questions / special characters and search

special characters and search

Views: 1,274

Results 1 to 12 of 12
8 Mar 2016, 5:15 PM
#1
earmsby avatar

earmsby

Zen Follower

Join Date:
Oct 2006
Location:
Worcester, MA
Posts:
451
Plugin Contributions:
0

special characters and search

I noticed something a bit odd with a client's ZenCart store recently. When running a search for a word that has a special character in it, some characters are found but some are not. Since I don't normally do much searching on the client's site, I'm sure it's always been like this but I just never noticed. I wondered if there was some logical explanation for this that is just escaping me.

Here's and example of what I mean:

Search term: "Bayoan"
Title Found: "Bayoán" [note A with accent above]

Search term: "uber"
Title NOT Found: "Übers Gebirg' Maria" [note umlaut U]

I haven't tried doing similar searches for foreign characters (like Ç or Ñ) that are like regular characters but it seems at least initially that some substitutions are made in the search but maybe not others? Is there a way to find out which are?

8 Mar 2016, 5:30 PM
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: special characters and search

Trying to look up the area of code for this, but was also wondering what charset(s) are in play here? Ie. Includes/configure.php, admin/includes/configure.php and includes/languages/english.php as well as the actual database itself (phpmyadmin).

8 Mar 2016, 5:38 PM
#3
earmsby avatar

earmsby

Zen Follower

Join Date:
Oct 2006
Location:
Worcester, MA
Posts:
451
Plugin Contributions:
0

Re: special characters and search

The charset for ZenCart is iso-8859-1 and the collation for the database is Latin-1 in case that helps with this question.

8 Mar 2016, 6:01 PM
#4
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: special characters and search

earmsby:

The charset for ZenCart is iso-8859-1 and the collation for the database is Latin-1 in case that helps with this question.

It could, but there is a more likely "cause" depending on what text is entered where.

The bulk of the search is performed in: includes/modules/pages/advanced_search_result/header_php.php

Look for the section that uses $keywords.

The search goes out and looks at multiple parts of the product for the information. So, the un-formatted version that is returning results may have the text entered in one of the searched fields other than what was posted above. Ie. Metatags, description, etc....

8 Mar 2016, 6:50 PM
#5
earmsby avatar

earmsby

Zen Follower

Join Date:
Oct 2006
Location:
Worcester, MA
Posts:
451
Plugin Contributions:
0

Re: special characters and search

Right. I thought of that at first but with my "Bayoán" example, the word without the diacritical mark "Bayoan" is not anywhere is the record. Maybe I'll poke around in the PHP file that does the search to see if I can find any clue. My gut feeling is that is has something to do with the charset itsel and less to do with the way the ZenCart search works. But my client thinks that I have set something to automatically translate these characters which of course I haven't. ;)

8 Mar 2016, 7:46 PM
#6
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,100
Plugin Contributions:
56

Re: special characters and search

Another thing to look for is whether the database uses HTML symbols instead of the actual characters themselves: é is not going to match é when searching.

9 Mar 2016, 3:20 PM
#7
earmsby avatar

earmsby

Zen Follower

Join Date:
Oct 2006
Location:
Worcester, MA
Posts:
451
Plugin Contributions:
0

Re: special characters and search

lat9:

Another thing to look for is whether the database uses HTML symbols instead of the actual characters themselves: é is not going to match é when searching.

Right, I also thought of that but neither of my examples are using the HTML symbols. Looking at the data directly in the database (via MySQL workbench) and also looking at the source code, I don't see html symbols.

Puzzling indeed. I will keep digging and post if I figure out what causes the difference.

9 Mar 2016, 3:29 PM
#8
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,100
Plugin Contributions:
56

Re: special characters and search

Check (as mc12345678 indicated previously) three values:

  1. /includes/configure.php, DB_CHARSET value
  2. /includes/languages/{YOUR_TEMPLATE}/english.php or, if a template-override doesn't exist, /includes/languages/english.php, CHARSET value
  3. using phpMyAdmin, check the default collation associated with the to-be-searched element.
    The values associated with the 3 settings should be similar, e.g. utf8, utf-8 and utf8_general_ci OR latin1, iso-8859-1, latin1_general_ci.
9 Mar 2016, 3:40 PM
#9
earmsby avatar

earmsby

Zen Follower

Join Date:
Oct 2006
Location:
Worcester, MA
Posts:
451
Plugin Contributions:
0

Re: special characters and search

The charset in both places in ZenCart is: iso-8859-1 and the collation is latin-1 as previously stated.

Further digging on this and I discovered two new things:

  1. The search works for at least some other characters (besides accents):

Search term: "sueno"
Title Found: "El Sueño de Tartini"

2. If I actually paste "Sueño" into the search box the search fails and the main home page is displayed - not even the usual no products found search results page.

More digging is next on the actual search code to see what's going on.

9 Mar 2016, 7:05 PM
#10
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,100
Plugin Contributions:
56

Re: special characters and search

I'm not sure what "both places" means relative to the CHARSET: Do you mean both admin and store? What about the DB_CHARSET, present in the configure.php files?

10 Mar 2016, 3:15 PM
#11
earmsby avatar

earmsby

Zen Follower

Join Date:
Oct 2006
Location:
Worcester, MA
Posts:
451
Plugin Contributions:
0

Re: special characters and search

lat9:

I'm not sure what "both places" means relative to the CHARSET: Do you mean both admin and store? What about the DB_CHARSET, present in the configure.php files?

I meant in both #1 and #2 in the list of three things you indicated. But yes it is also "iso-8859-1" in both admin and store.

At this point, I believe it has to do with the particular character since many other special characters are fine.

10 Mar 2016, 3:46 PM
#12
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,100
Plugin Contributions:
56

Re: special characters and search

That could be the issue; the DB_CHARSET value (present in the /admin/includes/configure.php and /includes/configure.php files) should be either *latin1 *or utf8, not iso-8859-1.