I'm trying to build my own search engine with MySQL. It gets a text like "Stackoverflow+MySQL+SearchEngine", splits it into array [Stackoverflow,MySQL,SearchEngine] and feeds to MySQL like in the following:
var text = filter.split("+");
var sql_statement = ' (title LIKE "%'+text[0]+'%" OR detail1 LIKE "%'+text[0]+'%") ';
for(var i = 1; i < text.length; i++){
sql_statement += ' AND (title LIKE "%'+text[i]+'%" OR detail1 LIKE "%'+text[i]+'%") ';
}
pool.query('SELECT thread_id,username,date,price,title FROM threads_mphp WHERE'+sql_statement+'ORDER BY thread_id DESC LIMIT ?, ?',[startLimit,amount], function(error,results,fields){});
The database checks if those words exist in either "title" or "detail1". The problem is, it only works only upto 3 words with independant order. If I use more words and random order it won't find the result in the Database. Am I doing something wrong?
Example: Database item Title:"First question in Biology". Strings that will find this item: "bio" ,"biology question","first question in bio", "bio first". Strings that wont find this item: "Biology in question first","biology question first"