Hi,
I need to make a simple and free site search tool on my website. It ideally would work like the one on this site, but even simpler. I want to be able to use a frame on the left to search and it would return a list of links which when clicked open the page at that location or something. Does a simple free script exist?
you should be able to write one pretty easily, all you need to do is keep a list of all the pages on your site, or give it access to all the sources of text you use (such as an sql database)
then you load them as a string (one at a time) and parse them for the search terms, when you get a hit, you keep that page's url handy and give it a score, each hit adds to the score, and then once you've checked all the pages, you arange them in order of the most hits...
that would mean, if you search for FPS, the page that has "FPS" on it the most will be at the top of the list... giving it some semblance of order
It sounds a lot harder than it is.... to break it all down.
Gather all your data.
Parse the data for the search term.
Arange.
Print.
and each step isn't very hard... the problem is that the more pages or data you have, the slower and slower the search will be... But if you have less than about 1000 pages... it shouldn't be too bad.
I wouldn't really break each step into it's own section like that in code, tho..
I would grab a page from the list or the first entree in the database, parse it, add a score, and save the URL and the score to some kind of variable... 2 arrays would be fine.
Then I'd reorder the arrays by the score and print out the URLs.
You could link to Google and get it to return results for just your site.
Thanks perturbatio, sounds most likely! And thanks for everyones reply.
bear in mind that it needs to spider the site, you can manually run it, or set up a cron job (most decent hosts have a facility for doing this via the backend).