If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > thesaurus

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-08-04, 23:49
ueberkracher ueberkracher is offline
Registered User
 
Join Date: Jul 2004
Posts: 1
thesaurus

hello,

i am implementing a thesaurus function with php and mysql.

herefor we have table 'thesaurus ' in which all words are stored and grouped. every word has a group name. i. e.:

word: 'mercedes' -> group: 'cars'
word: 'bmw' -> group: 'cars'
word: 'ford' -> group: 'cars'

word: 'george bush' -> group 'warlords'
word: 'osama' -> 'group 'warlords'

etc...


if someone is looking for 'mercedes' the search shall not only match records including this word, but also bmw or ford. several columns are searched (i. e. title, date, details).

i could do that with a lot f php commands and a lot of mysql queries. but actually i want to to it only with sql.

can you help me? i am desperating on that. thanks and best,

uek
Reply With Quote
  #2 (permalink)  
Old 07-09-04, 00:04
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
try a self-join

Code:
select t1.stuff , t2.word
  from thesaurus t1
left outer
  join thesaurus t2
    on t1.group
     = t2.group
   and t1.word <> t2.word  
 where [search conditions]
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 07-09-04, 00:21
jvanv8 jvanv8 is offline
Registered User
 
Join Date: Feb 2004
Posts: 7
The main thing you need to think about is the db structure. Get the structure right and the queries are much easier.

Here is what I would do. I wasn't sure what you were linking your words to... for simplicity, we'll assume the keywords are for news articles

Table: keyword (keyword_id,word)
Table: group (group_id, group_name)
Table: keyword_group (group_id, word_id)
Table: article_keyword (article_id, word_id)
Table: article_group (article_id, group_id)
Table: article (article_id, title, date, details)

Then your query would just be
SELECT whatever FROM keyword AS K
INNER JOIN keyword_group as KG ON K.keyword_id = KG.keyword_id
INNER JOIN article_group AS AG ON KG.group_id = AG.group_id
INNER JOIN article AS A ON AG.article_id = A.article_id
WHERE K.word = '" . $search_term . "'"

Basically you need a way to group an article with a group and a group with a word. I didn't put anything in the query to return cases where an article is directly associated with a word in the article_keyword table but thats easy enough to do.
- John
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On