Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,515 members, 7,808,881 topics. Date: Thursday, 25 April 2024 at 06:34 PM

A Quick Alternative To Mysql Fulltext Search - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / A Quick Alternative To Mysql Fulltext Search (2031 Views)

Localhost Not Allowed To Connect To MySQL. Help!!!! / Connecting My Dreamweaver Site To Mysql Database / How Do I Connect A Form To Mysql Database (2) (3) (4)

(1) (Reply)

A Quick Alternative To Mysql Fulltext Search by elvis10ten(m): 9:33am On Apr 27, 2013
I just thought of this quick alternative to mysql full text search. I have not tested it though, but you can tell me if it works for you.
LETS GET STARTED
Sometimes you might want to search multiple string in one query or if any of the word in a long text occured in your database. You can do this using OR manually:
SELECT * FROM mumu WHERE name = firsttext OR name = secondtext What will happen if you have 10,000 words to check, you will write till your finger hurts. FUNNY SOLUTION
If you are taking each word from your database, iterate through the result and store each in an array, after the loops exit explode it with " " as a delimeter. Or if its a long text just store in a variable. Then you implode the variable with " OR column = ". Then put in your mysql query like this "SELECT * FROM table WHERE column = $variable".
END OF STORY. ITS A SIMPLE SOLUTION. There are other better solution out there, incase you are fed up with the mysql fulltext word length limit and you can't change it. THIS METHOD CAN BE MANIPULATED TO FUNCTION LIKE MYSQL FULLTEXT IN BOOLEAN MODE. JUST BORED
Re: A Quick Alternative To Mysql Fulltext Search by elvis10ten(m): 11:02am On Apr 27, 2013
PHP CODE:
<?php
include("connect.php"wink;
$msg = $_POST["msg"];
$filter = $_POST["filter"];
$hay2 = explode(" AND column != ", $filter);
$hay = explode(" OR column = ", $msg);
$query = $db->query("SELECT id, column2, column3, column4 FROM table WHERE column4 = '".$hay."' AND column4 != '".$hay2."' LIMIT 100"wink;
/*IF THE COLUMN YOU ARE SEARCHING AND THE VARIABLE USED FOR THE SEARCH CONTAINS MORE THAN ONE WORD, YOU CAN BUILD A RANK FOR THE RESULT BASED ON HOW MANY WORDS WERE FOUND. IT WORKS WITH AN ID.*/
$words = explode(" ", $msg);
$frequency = array_count_values($words);
//fast way to remove duplicate
array_flip(array_flip($words);
//You can use a stop word dictionary to remove stop words.
$ids = array();
$rank = array();
while($row = $query->fetch_assoc()) {
foreach($words as $value) {
if(in_array($value, $words)) {
if(isset($rank[$row["id"]]))
$rank[$row["id"]] += $frequency[$value];
}
else {
$rank[$row["id"]] = $frequency[$value];
}
}
}
$ids = $row["id"];
}
/*You can use other ways of ranking or other algorithms like tf-lf, etc. This one just use word frequency to determine the rank.*/
Re: A Quick Alternative To Mysql Fulltext Search by danvery2k6(m): 8:55am On Apr 28, 2013
Nice work brother. Looking forward to seeing healthy contributions like this on Nairaland

1 Like

(1) (Reply)

I Just Finished Learning Php Through Video Tut , Now Whatt Next? / Chat GPT Can Lie Oo!! Here What It Says About Peter Obi!!?? / Software Development On Java

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 12
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.