PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Basically, i have a database full of articles. i need to be able to search through the entire database and pull up a list of all relevant articles (similar to how the forums search function works). I dont want to have to ask the user for specific keywords, because as well all know, the user is stupid
So what im asking now is, how would i go through creating this search? i dont need specific code necessarily, just some ideas or maybe a link to an algorithm or something
Pickle is right in that you have to search for SOMETHING...
I would use a full text indexed field on the MySQL database and do a MATCH AGAINST query to see if there are any relevant matches. With full text indexed fields it doesn't have to match exactly as it's entered for the search criteria...
for example:
searching for: "my dog has big teeth"
could return: "this is an article about dogs, dogs have teeth that are big"
lemme know if you need some help setting up the index or if you need query syntax help.
Ya, FULLTEXT is probably the way to go. However, depending on the context, it may not be.
FULLTEXT does not work if you want to use wildcards, you'll have to use LIKE syntax for that.
For example, if I want to search the database for 'Madagascar', but I don't know how to spell it, I could type in "Mad%car" in the search field and search for that string using LIKE. Using FULLTEXT, however, it will just return entries that have the literal string 'Mad%car' in it.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
yup that's what you want....but that is NOT exactly how the phpBB forum search works...it's more like a google approach to searching whereas the forums use keywords and separate them by spaces.
if you search for "dog biscuits, rabbit gravy flavored", in the forum search it's going to do a literal search for those words (anywhere in the "article") but the full text search doesn't care if all of the words match, nor the placement of the words. It uses a pretty complex algorithm to determine if articles match based on the search string (placement of words in the search string and placement of words in the searched text) then fetches results based on weight.
you can actually display the results by most relevant at the top, and then move downward as the results stray further from the search text. (just like a search engine).
as I posted before, if you need any help with the sql syntax, lemme know. Having them ordered by the most relevant is not super intuitive and not well documented (at least it wasn't when I started doing it).