SB24
SB24

Reputation: 531

php : improve my search results

I have a search function in my website.

Well anyways, there is such text in my website like: "čurti" "čuožžut" and so on...

The problem is that when user searches with word "curti" not "čurti" it should find the page.

Some code to help to understand:

$search = trim(mysql_escape_string($_POST["search"]));
$result = mysql_query("SELECT * FROM wt_pagesearchwords WHERE word='$search'");

You can see the part: word='$search'... so if user searches with word čurti, it will be like:

$search = čurti;
$result = mysql_query("SELECT * FROM wt_pagesearchwords WHERE word='čurti'");

But that's not enough. I need it to convert the čurti to curti...

Detailed question: I have a empty single page that has only 1 search word, it is čurti... but if user searches with curti, it should also find that čurti although it's spelled in otherway...

This question is much like the Google search's "Did you mean blah blah?" when search returned nothing.

Anyway understood? Sorry my bad English

Thanks anyways,

Upvotes: 3

Views: 285

Answers (3)

Darm
Darm

Reputation: 5659

You can update your collation table field of 'search' to 'utf8_general_ci'.

Upvotes: 0

PeeHaa
PeeHaa

Reputation: 72681

Instead of doing a Did you mean you could also add the normalized words to your searchtable.

So that the page will be found whether it is searched by čurti or curti.

You could use iconv for this:

$text = iconv('utf-8', 'us-ascii//IGNORE//TRANSLIT', $text);

Or you could add a wt_pagesearchwords_normalized field which holds the normalized keyords.

Now if no search results come up if you search the field wt_pagesearchwords you could search the wt_pagesearchwords_normalized field for a did you mean.

Upvotes: 1

eaj
eaj

Reputation: 2618

Your database needs to be configured for both the correct character set and the correct collation so it knows which characters are to be considered equivalent.

Your question is probably a duplicate of this one.

Upvotes: 0

Related Questions