My database has almost 15.000.000 entries. Each entry is a phrase and each phrase starts in upper case and ends in a point (.) ex: "This is a sample phrase."
I need to get 10 random phrases that contain a specific word ( $q ). Because $q can be in the beginning of the phrase i will use also $q_upper for the query.
Using this query:
$res = mysqli_query($db,"SELECT quotes FROM corpus WHERE quotes LIKE '% ".$q." %' or quotes LIKE '% ".$q.".' or quotes '".$q_upper." %' order BY RAND() LIMIT 10");
Because its a large database it takes around 10 sec and a lot of resources to deliver results.
Is there a way I can optimize this query (or maybe split the database ) in order to make it efficiency.