Hi guys, I have a search on my site that works great (in part thanks to you), but I'd like to add a thesaurus (of sorts) to it. When keyword entered function thesaurus is my idea. Function thesaurus{ jim=gym; jem=gym; jimm=gym; pe (short for physical education)=gym; p.e.=gym; exercise=gym; } etc. Is this the best way to do something like this? Thoughts, suggestions? Thanks
I think that's how it is done...But you'd use an array...If it's php I'm not sure what you are TRYING to accomplish exactly, but yeah.
Search is great, but some people can't type or spell to save their lives, or worse yet, might use a different word altogether than the one(s) in the search field (in the DB). So, I'd like to work around this by returning results that I have that take spelling errors, etc. into account. A filter of sorts that will replace their word/spelling for the one that is in my DB (that will return results). If the DB was small, I could go through manually and add the different spellings where needed. Unfortunately, it's getting rather large, and I don't want to have to export it (who knows how often) to a csv file, search and replace in excel (or the likes), and then upload it again every time I realize I should have a different spelling or word for a category or field. So, if I have gym as a search term in my DB, P.E. (physical education - which I didn't think to enter in the relevant categories when I made the DB) will be compared in a lookup table, and gym results will be returned.
Building one, is not hard. The challenge is filling out a database to power it. Try to find a site that lets you add their api to your site.
Ok, got a DB set up for my thesaurus and a somewhat functioning script. Only real problem I can see (right now) is that if $keyword is not found in the thesaurus table it defaults to the $keyword that was found (so if there is more than 1 keyword and 1 isn't found, it returns the found keyword twice). This isn't good as I need the keywords found or not (matched or not) for the second query of the table where the main data is stored. Help? for ($i=0; $i<(count($keywords)); $i++){ $thesaurus_query = "SELECT * FROM " . $thesaurus_tbl_name . " WHERE "; $thesaurus_query .= " thesaurus LIKE '%".$keywords[$i]."%'"; $thesaurus_query .= " ORDER BY id"; $thesaurus_result = mysql_query($thesaurus_query) or die(mysql_error()); while ($row = mysql_fetch_object($thesaurus_result) ) { $thesaurus_keywords .= $row->base_word; } } $keywords = $thesaurus_keywords;
Yes, it is, but maybe I've complicated it by calling it a thesaurus. It's really a lookup/compare and replace script. It has to be able to take multiple words, because the original search on the site takes multiple words (can't tell users only one word per use). How can I put a space between words? The way it works right now, if I echo $keyword it displays: keyword#1keyword#2 (so, it must be stored without spaces, yes?).
Ok, think I got it. Thanks any way guys. Forgot it was an array, so needed to keep working with it as an array.