Ozzii
Full text indexes are optimised to work around words and sentences and may have difficulty making any sense out of your formula field containing "
CN1C=NC2=1C(=O)N(C)C(=O)N2C". You may find it quicker to search this field using a normal index. If the chemical name field is made up of discrete words then this might be a good candidate for the full text search (assuming you want to search on this).
However as guelphdad pointed out, searching for
"%string%" won't work well with normal indexes either. Indexes are usually organised with B-trees that allow the database to quickly navigate to the right key item - so if you searched for "
CN1C%" the database could jump to those key items beginning with
C then jump to those starting with
CN and quickly get to your answer. If your search string starts with % then the database wouldn't know where to jump to and would instead have to scan each item in the index (or just do a table scan) and this takes far more time. I found this
link which covers some of this.
It really depends on how many chemicals you have in your database - if there aren't that many then you might find it doesn't really matter. Could you try both types of index (and perhaps no index at all) and see which is faster. It would be interesting to see the comparisons.
If things are still slow then could you create your own caching table where you might want to look for common substrings in the formula field and then extract all the chemical_ids that contain it. Then if a user searches for one of these substrings you can just get the chemical_ids directly from your cache table without any searching. Another method might be to simply cache all the user searches and the ids returned then use this cache if the search string has been used before - you may want to repopulate the matches automatically if there is a lot of change in your database.
Just my 2cents.
Mike
Edited to try and make more sense.