I would like to build a search function for a custom-built CMS.
Apart from just searching for a keyword in the page title and text, I would like to sort the results according to where the keyword was found.
E.g.
If I search for 'contact', and they keyword is found in the page title of page 1, but only in the body of page 2, it would show page 1 at the top of the search results.
Some ideas I had for doing this are:
do a MySQL search 'SELECT * FROM pages WHERE title LIKE '%$keyword%'
save results into an array
do another MySQL search 'SELECT * FROM pages WHERE body LIKE '%$keyword%'
save results into an array
merge arrays 1 and 2, sorting by array 1 (and removing duplicates)
Not sure how to just grab a snippet of text from MySQL when searching...
Another issue is, do I search for a keyword 'string', or split up the keywords when searching?
Any thoughts?