Jump to content


Photo

best way for store and find keyword matches php mysql


  • Please log in to reply
2 replies to this topic

#1 Nomax5

Nomax5
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts
  • LocationYork England

Posted 11 September 2006 - 09:00 PM

I'm coding a website link management thing
I'm storing website details: url, title, description, and keywords.

What I want to be able to do is identify releated websites. it doesn't have to be perfect
I present them to the visitors as "possibley related websites"

My initial idea was put the keywords in seperate fields and to do multiple searches one keyword at a time.
but I'm thinking perhaps I should create a full-text index and do something better.
perhaps seach the title and the description also

suppose I had a string of keywords "fish,fishing,fish scales,fish tail, shark,fishing rod"

You guys are usually really good at comming up with ideas, I thought I'd ask for your ideas before I build the tables

Cheers

Roy
 

#2 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 11 September 2006 - 11:44 PM

I normally do these open searches.  Like I have a form

<form name="searchform" id="searchform" action="whatever.php" method="get or post">
<label for="searchtext">Search</label>
<input name="searchtext" id="searchtext" type="text" maxlength="120" />
<br />
<input name="searchsubmit" id="searchsubmit" type="submit" value="Search It!" />
</form>

THen you can process it, and when you do, run a special query, with the query have it check everyfield of everydatabase.  With 2 percentages, this makes it guarantee any close match, for any field.
Like this

<?php
$search = mysql_real_escape_string($_GET['searchtext']);
$search = strtolower($search);
$select = "SELECT * FROM tablename WHERE url LIKE '%$search' OR title LIKE '%$search' OR description LIKE '%$search' OR keywords LIKE '%$search';";
$query = mysql_query($select);
if ($row = mysql_fetch_array($query)) {
// do whatever 
}
?>

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#3 Nomax5

Nomax5
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts
  • LocationYork England

Posted 12 September 2006 - 10:41 AM

ahh thanks businessman332211

I'll fiddle with it.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users