Current location: Hot Scripts Forums » Other Discussions » Database » Full text search issue


Full text search issue

Reply
  #1 (permalink)  
Old 10-13-09, 06:39 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 704
Thanks: 0
Thanked 0 Times in 0 Posts
Full text search issue

Hi there,

I'm making a full text search for my website. Now I get a problem if the
table are not build with the same fields.

F.E.

table_1 -> title, story, comments
table_2 -> title, story, comments, links
table_3 -> title, comments, tips
table_4 -> comments, links, transportation

PHP Code:

$search_result_algemeen mysql_query(

"SELECT * FROM table_1 WHERE MATCH(title, story, comments) AGAINST($word IN BOOLEAN MODE) 
 UNION SELECT * FROM table_2 WHERE MATCH(title, story, comments) AGAINST(
$word IN BOOLEAN MODE)
 UNION SELECT * FROM table_3 WHERE MATCH(title, comments, tips) AGAINST(
$word IN BOOLEAN MODE)
 UNION SELECT * FROM table_4 WHERE MATCH(comments, links, transportation) AGAINST(
$word IN BOOLEAN MODE)
 "
) or die('Error, query failed'); 
It should be something like above..
but there are some errors... where did I go wrong and is there a way to do somthing similar?

_j
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 10-16-09, 08:38 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Try it like this:
PHP Code:

$search_result_algemeen mysql_query
"SELECT * FROM table_1 WHERE MATCH(title, story, comments) AGAINST('$word' IN BOOLEAN MODE)  
 UNION SELECT * FROM table_2 WHERE MATCH(title, story, comments) AGAINST('
$word' IN BOOLEAN MODE) 
 UNION SELECT * FROM table_3 WHERE MATCH(title, comments, tips) AGAINST('
$word' IN BOOLEAN MODE) 
 UNION SELECT * FROM table_4 WHERE MATCH(comments, links, transportation) AGAINST('
$word' IN BOOLEAN MODE) 
 "
) or die('Error, query failed'); 
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 10-17-09, 08:13 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
You could use SHOW COLUMNS and build a query with all character fields.

I can't test this because my server is running MySQL 4 - but if you have 5.0+, this might be worth a try.

SHOW COLUMNS FROM `evo_items__item` WHERE `Type` REGEXP "^varchar";

MySQL :: MySQL 5.0 Reference Manual :: 12.5.5.5 SHOW COLUMNS Syntax

The approach would be to run the SHOW COLUMNS query to get the character and varchar columns (as well as any others you want), then construct your text search query to search those columns. That way, as you add more tables, and more columns, the code doesn't have to change. You can also use the SHOW TABLES command to find new tables.

Naming the tables and columns can help here. For example, you wouldn't want to allow most users to search the user table, so you could prefix private table names with an underscore.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
text box with scroll bar silvermane CSS 7 01-16-09 04:03 AM
div css theighost CSS 11 09-14-08 03:30 AM
Draggable Tables Ares JavaScript 10 08-03-06 07:55 AM
Give your Search Position a BOOST! Get 10000+ Text Links Leading to your Website! IncognitoNet General Advertisements 0 06-19-05 11:53 PM
picking random entries with a filter... Double selection problem dsumpter PHP 7 11-16-03 08:19 PM


All times are GMT -5. The time now is 01:12 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.