The previous reply from allolex offers some very good advice on how to approach this problem. In addition to the direction offered in that reply, you may want to have a look at the Perlfect search engine which is written in Perl and implements a very basic stem indexing method.
in reply to term weight
There has previously been a discussion on stemming from the perspective of stemming errors at Natural Language Index Stemming.
perl -le 'print+unpack("N",pack("B32","00000000000000000000001000111001"))'