Weighted search results using MySQL LIKE

  • May 7, 2013
  • MySQL

Using LIKE, instead of the usual MATCH AGAINST using FULLTEXT. Here’s the query i’ve made to search events: [code] SELECT id, title, date_from, IF (`title` LIKE ‘%$searchTerm%’, 20, IF (`content` LIKE ‘%$searchTerm%’, 10, 0)) + IF (`content` LIKE ‘%$searchTerm%’, 10, 0) + IF (`venue_name` LIKE ‘%$searchTerm%’, 5, 0) + IF (`venue_address` LIKE ‘%$searchTerm%’, 5, 0) […]

Dynamic Object Names – Navigating to method declarations in php storm

One of the things I love about PHPStorm is the way i can navigate to any function or method declaration just by cmd-clicking it (or ctrl-clicking on Windows), except when using dynamic object names. However, there is a problem when you have a dynamically named object. Here I outline the problem, and also the solution, […]

Minify HTML using PHP

Just playing speeding up page, even if it is by milliseconds…! So i decided to minify my static html. preg_replace being as powerful as it is, makes life easy: [code] function minifyHTML($html) { return preg_replace( array(‘/<!–(.*)–>/Uis’, "/[[:blank:]]+/"), array(”, ‘ ‘), str_replace(array("\n", "\r", "\t") , ” , $html) ); } [/code] preg_replace works literally like this: […]

Starting a new project with Cubex framework in PHP Storm

Using PHP Storm to create a new project using the Cubex Framework. In PHP Storm Starting with File > New project. You need to do three things: give the project a name choose a location choose a project type The first two are up to you, for the project type, choose “Composer project”. Next you […]

simple contrast colour in php

I’m just building a website for my small anti-spam verification code, vericode. There are a few configurable options, background colour being one of them, and to make sure the text is still visible, i used the following PHP to do a simple test against “half of white”, and return either black or white text: [code] […]

linking to internal pages using ckeditor 4

It’s functionality that already exists in other editors such as tinyMCE, i am surprised that linking to internal pages using ckeditor cannot be acheived in an easier (native built-in) way. So, when i develop CMS’s for various clients, i always use CKEditor, and 9 times out of 10, the client needs to link to internal […]

fetching wordpress posts using google feeds api

Building my new website (again) and decided to feed one of my existing blogs to it, using javascript to pull in the content after the main page has loaded, usual style… i decided to use the google feeds api for fetching wordpress posts. here’s my html: [code] <div id="feeds"> <h3>From Tizards Briefcase</h3> <div class="feedBox" data-url=""> […]

jquery 1.9 – adding handlers after dom load

Just started a project using jQuery 1.9 and immediately got stuck with adding handlers to elements that are created after the dom has loaded, i simply did: Prior to jQuery 1.9, adding a click (or any handler for that matter) to an element after the DOM has loaded used to be a matter of using […]

WordPress-like slug generator

I’m building a site for a client at the moment that needs to be able to control the URLs for each of their pages (including sub pages etc), we need a WordPress-like slug generator! So, I came up with this, which i imagine is very similar to WordPress achieve the same thing (essentially stripping out […]