HTML & CSS
Want to add a "search" feature to my website, and wondered if someone can recommend a good code or program.
I experimented with the Goodle code, and while it's good, it's doesn't always take the visitor to the correct place
(i.e. it will sometimes just take to you the top of the page, not the article or item in question). Then again, maybe I am wrong in how these things work.....?
You would probably need to be using a content management system to have a search function for your site. I have used the native CMS search functionality a few times, but to be honest, I find the Google search function to be much better anyway. Google sees much more on your site that your CMS ever will, so it gives better results. It's not ideal that the user gets taen to the Google site to see the results, but you can't have everything.
The advantage of using Google is that most user will be familiar with the interface. Furthermore, advanced users might prefer not to use local search engines, as most are quite poor. Building a proper search engine isn't exactly trivial, especially if you want to be able to do fuzzy searches. I would suggest experimenting a bit more with Google, before you give up on it, and ask here if you have any specific problems (I'm not sure what you mean about being taken to the top of the page).
For instance, when I typed in a specific word, it would simply take you to the top of that page, not to the article or comments that included the word. A few of my pages are quite long...
This why it's a good idea not to have too much content, or diverse topics in depth, on a single page.
If you cannot reduce the amount of content by sorting it into separate pages, adding a list of in-page links at the top of the page may help visitors find what they're looking for, once landed. This would require adding ids to elements that identify sections, such as headings, and making the id the href target of the link anchor. e.g.
In-page links list
<p>Elephants are well known for their large size, grey colour...</p>
A good search function is not quite trivial. You would have to alter the content when printing it out and add <a name="#pos1">first match</a> or something like that around all your matches (while avoiding collisions with existing anchors, and without breaking any existing html), then the browser can scroll to the first match.
However there is much more to it; you would have to do some stemming on your search input and all your content and then decide which of your pages is the closes to the search input, while mostly ignoring all the stopwords you may encounter.
Find a plugin for your cms that, or use google site search. There probably wont be any "a good code or program" that works out of the box for any site, since it has to hook in to your existing cms and create it's own db tables so it can pre-index and score your content etc.
Personally I've always liked Sphinx: http://sphinxsearch.com/about/sphinx/
You might want to consider Freefind. I used it on one of early sites, and it seems to have provided a good service. They have a free option, which has advertisements on the search results, and a paid-for option which is ad-free.
That said, I tend to use Google now, mainly because it's a leading brand name.
If you need free internal site search without ads for a small website then you may want to check Findberry. It is a hosted commercial service, but it is free for sites with 200 pages or less (no ads and you can specify your own design by means of HTML/CSS).
You should know - my suggestion is biased, because I'm one of the designers at Findberry.