There's a simple algorithm that uses the Bayes theorem that can be used to classify documents, using their text tokenized into individual words, into categories (e.g. tags on a website). The classifier needs to be trained with existing data, and then it will return which categories a new document probably belongs to.

Here is an implementation in PHP, which I used for the document uploading process in the ShelterCluster.org website: https://github.com/kbariotis/documer

Latest on PHP