The idea here is to have a basic full text search engine, which accepts documents and creates a searchable structure.
I'm kinda using a tf-idf based idea, and took some inspiration from MySQL's internals for their Fulltext index. I added more robustness to the ranking algorithm by giving weightings a boost when an exact match of part of the query is found. Of course, it's not an exact science, and could do with a lot of improvement, but I think it's a pretty cool start.
Additionally, I've tried to write it using backwards compatible javascript for browser acceptance.
There are two objects: documents, and terms. Every time a document is inserted, the terms are tokenised and given weights. We also keep track of the word after each term to strengthen our ranking system. Documents are also stored, with their meta data, so that they can be retrieved with the results.