thesaurus

Discussion in 'PHP' started by lektrikpuke, May 24, 2008.

  1. #1
    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
     
    lektrikpuke, May 24, 2008 IP
  2. lektrikpuke

    lektrikpuke Well-Known Member

    Messages:
    297
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    113
    #2
    A filter and substitute and thesaurus.
     
    lektrikpuke, May 24, 2008 IP
  3. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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.
     
    NatalicWolf, May 24, 2008 IP
  4. lektrikpuke

    lektrikpuke Well-Known Member

    Messages:
    297
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    113
    #4
    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.
     
    lektrikpuke, May 24, 2008 IP
  5. itnashvilleCOM

    itnashvilleCOM Banned

    Messages:
    176
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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.
     
    itnashvilleCOM, May 25, 2008 IP
  6. lektrikpuke

    lektrikpuke Well-Known Member

    Messages:
    297
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    113
    #6
    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;
     
    lektrikpuke, May 25, 2008 IP
  7. itnashvilleCOM

    itnashvilleCOM Banned

    Messages:
    176
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #7
    The thesaurus is meant for one word at a time, I think you are overcomplicating it.
     
    itnashvilleCOM, May 25, 2008 IP
  8. lektrikpuke

    lektrikpuke Well-Known Member

    Messages:
    297
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    113
    #8
    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?).
     
    lektrikpuke, May 26, 2008 IP
  9. lektrikpuke

    lektrikpuke Well-Known Member

    Messages:
    297
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    113
    #9
    Ok, think I got it. Thanks any way guys. :D Forgot it was an array, so needed to keep working with it as an array.
     
    lektrikpuke, May 26, 2008 IP