March 27, 201511 yr I've created a database search function an have encountered a problem I don't know how to fix. The problem is that the database content contains html formatted word breaks in long words. The database entries are in Danish (a language where we don't split connected words). Example: The english word(s) "Multimedia project" would be just one word in danish ("Multimedieprojekt") so in the database the word is stored as "multimedieprojekt". The allows the word to be divided at line breaks with CSS hyphens. As a result the word "Multimedieprojekt" will not show up in search results because the word technically doesn't exist in the db. So the question is: Is there any way I can filter out $shy; wordbreaks in my db-query or do I have to load all db entries and filter the results in PHP? Here's the important part of the search function //input from the search form $sanitized = filter_var($_GET['search'], FILTER_SANITIZE_STRING); //The returnConString function creates a new PDO instance $con = returnConString(); //Store matches between the input and the content in an array declared earlier(CONTENTTABLE is just a constant representing the table) $queryPost=$con->prepare('SELECT post_id, post_title, content FROM '.CONTENTTABLE.' WHERE content LIKE :keywords'); //binding the input as a param in the querystring $queryPost->bindValue(':keywords', '%' . $sanitized . '%'); Edited March 27, 201511 yr by Nillervision
March 27, 201511 yr Author I think there are two or three options here: 1) Bring out all of the data and then use PHP to filter it. I don't think this is very efficient though. 2) Add an extra column in the database that has the same data in it but without the ''s and search on that. 3) See if you can use CAST to 'copy' the column without the ''s. I'm not sure if this is possible. But Google might drag up some useful info. Thanks NOCK. I'm beginning to think option two with a keyword index it might be the best idea. It will also be more efficient as i can remove a lot of insignificant words. I don't think option 3 will work. I thought CAST was only used to return data as a specific datatype. Can it also be used to return altered content?
Create an account or sign in to comment