I've implemented a database with product names, descriptions, type,etc and I implemented at first a simple search code that send a productid (primary key on MySQL), through JSON to PHP that generates a Query on tha remote server. so, now I want to implement a search where the user can insert more than word on the search bar and the query return all products that match the words. For example, if the user search "green chair" I wnat the query to give back all the products that have the word green on the field colors and have the word chair on the field product. Any Idea that how do I have to implement this?
what are the main issues of using a query like this:
SELECT * , MATCH () AGAINST ('$search') AS points FROM productstb WHERE MATCH (PRODUCT,DESCRIPTION) AGAINST ('$search') ORDER BY points DESC LIMIT 50
I read that it generate problems when you use a lonly word is this true?
solved: I used this PHP file to take care of everything, thanks for all the hints, they were very usufull, also I tried using lucene is faster especially for long n data bases, but unfortunately I cannot decide to move to a lucen DB
<?php
mysql_connect("localhost","root","soltux");
mysql_select_db("baseDatosMobil");
$search = $_POST['precio'];
$parts=explode(" ", $search);
$number=count($parts);
if ($number==1) {
$quer="SELECT ARTI,PRESENT,PRECBOL,PROV,CODART FROM PRODFAR WHERE ARTI LIKE '%$busqueda%' LIMIT 10";
}
elseif ($number>1) {
$quer= "SELECT ARTI, PRESENT, PROV,CODART, PRECBOL, MATCH ( ARTI, PRESENT, PROV ) AGAINST ( '+$search' ) AS Score FROM PRODFAR WHERE MATCH ( ARTI, PRESENT, PROV ) AGAINST ( '+$search' ) ORDER BY Score DESC LIMIT 10";
}
$q=mysql_query($quer);
while($e=mysql_fetch_assoc($q)){
$e['ARTI']=utf8_encode($e['ARTI']);
$e['PRESENT']=utf8_encode($e['PRESENT']);
$e['PROV']=utf8_encode($e['PROV']);
$output[]=$e;
}
print(json_encode($output));
mysql_close();
?>