I'm considering writing a forum (of sorts, not the standard type like this), which all seems simple enough for someone with the PHP and MySQL experience that I have. However, there is one aspect I can't see a good solution to - the search function. I say this is for a forum but the theory (which is the problem, converting theory into PHP shouldn't be an issue) should stand for all searchable things like this, from the forum to a news posting script or whatever - I need to search through one or 2 fields in a table for some strings.
I want to have a box where the visitor enters the word or words they want to search for. Then there is a dropdown box or set of radio buttons where they select from the options "any word", "all words" or "exact phrase". There would be other options like by a certain member or within a time period, but these are no problem. They click on search and the script displays some details too all threads (or news articles or whatever) which contains any of the words, all of the words or the exact phrase.
I could implement a slow and painful method which would work by reading all entries in a table and individually searching the relevant fields, but that is both slow to implement and very slow to run. I can't see how to searching cut it down significantly, preferably cut down by the database. Obviously I can use WHERE and LIMIT sql parameters to cut out entries outside a set time or by a certain poster, but this leaves a lot of slow looping through returned fields for the PHP script to do.
Is there a way to get the database to search through the field(s) and narrow the results down?
Question
Quboid
I'm considering writing a forum (of sorts, not the standard type like this), which all seems simple enough for someone with the PHP and MySQL experience that I have. However, there is one aspect I can't see a good solution to - the search function. I say this is for a forum but the theory (which is the problem, converting theory into PHP shouldn't be an issue) should stand for all searchable things like this, from the forum to a news posting script or whatever - I need to search through one or 2 fields in a table for some strings.
I want to have a box where the visitor enters the word or words they want to search for. Then there is a dropdown box or set of radio buttons where they select from the options "any word", "all words" or "exact phrase". There would be other options like by a certain member or within a time period, but these are no problem. They click on search and the script displays some details too all threads (or news articles or whatever) which contains any of the words, all of the words or the exact phrase.
I could implement a slow and painful method which would work by reading all entries in a table and individually searching the relevant fields, but that is both slow to implement and very slow to run. I can't see how to searching cut it down significantly, preferably cut down by the database. Obviously I can use WHERE and LIMIT sql parameters to cut out entries outside a set time or by a certain poster, but this leaves a lot of slow looping through returned fields for the PHP script to do.
Is there a way to get the database to search through the field(s) and narrow the results down?
Link to comment
Share on other sites
7 answers to this question
Recommended Posts