Jump to content

best way for store and find keyword matches php mysql


Nomax5

Recommended Posts

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
 
Link to comment
Share on other sites

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

[code]<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>[/code]

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

[code]<?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
}
?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.