LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-20-2010, 09:34 PM   #1
MALDATA
Member
 
Registered: Mar 2005
Posts: 157

Rep: Reputation: 19
Implementing a variable-length list of keywords in mysql


There's probably a better forum for this, but honestly, I don't want any more accounts, so I'm just gonna float it here and see if someone knows. I'm having a hard time googling for answers because I keep using the word "keyword."

I've never really used any kind of database before, but I want to learn the basics, so I'm playing with it a little bit at work. What I want to do is make a database to hold information on various articles. For example, with columns for the title, author, and date. Those are all easy. The tricky part is that I'd also like to be able to label articles with keywords so I can search for certain topics.

Since there's no way to know ahead of time how many keywords, if any, each article might warrant, I'm not sure how to put this in database form. There's no variable-sized array data type. It seems sloppy to just list them all in a single VARCHAR column. Making several columns that may or may not be left null and putting one keyword in each seems wasteful.

Any thoughts?
 
Old 09-21-2010, 02:22 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
I confess up front that it has been a while since I used MySQL or any other SQL (ah, for the days of dBase).

I don't see any reason why you can't have just one VARCHAR field for all keywords. Make the field long enough to hold what you expect to be the maximum number of characters plus delimiter(s). No spaces between keyword and delimiter would probably be a good idea also. In your query, specify the keywords and the delimiter. It may seem sloppy, but that's the way it's done to minimize the amount of wasted disk space (in re your comment about using multiple keyword columns)

Hint: sit with pen and paper. Look through a variety of articles and choose keywords for each article. Write them down, one article after another. Then decide which articles could still be found by reducing the number of keywords (and characters/delimiters). Then adjust the size of the field accordingly.

Last edited by bigrigdriver; 09-21-2010 at 02:35 AM.
 
Old 09-21-2010, 09:56 AM   #3
MALDATA
Member
 
Registered: Mar 2005
Posts: 157

Original Poster
Rep: Reputation: 19
Sounds good. I have no real objection to doing it that way, but I wanted to get the opinion of someone who has done this before (even if it's been a while). I've done a lot of object-oriented programming, so when I can't just write a class that suits my data, I get a little lost...

Thanks!
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to parse files with variable record length btacuso Programming 4 08-11-2010 10:49 AM
Variable length console prompt statquant Linux - General 7 07-15-2010 05:55 PM
how to generate variable length packets in iperf rohit83.ken Linux - Networking 1 03-10-2009 08:53 PM
MySQL: search for pluralized keywords using RegEx? MicahCarrick Programming 1 09-26-2006 08:50 PM
Variable length objects kamransoomro84 Programming 4 10-28-2004 12:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration