I'm currently trying to implement a glossary functionality to one of my webprojects, it's all about:
- 50 - 200 "words" browsable in a glossary
- Up to 15 synonyms for each word
- Mostly dynamic contents to search for those words and replace with hyperlinks to the glossary content
The main problem i'm thinking about is the performance of searching through the mostly dynamic contents. My first approach loaded all words from the glossary into an array and search'n'replaced them with links in PHP using a regular expression.
Problem 1: The query
Loading up to 3.000 database tuples everytime someone refreshes a page doesn't seems to be a good idea.
Problem 2: The search
Doing such long loops with regular expressions with PHP doesn't seem to be a good idea, too.
Solution 1: Cached JavaScript
My first and only idea is to generate a javascript based list of the words and synonyms and let JavaScript to the replacements using regular expressions.
The final question
Is my solution a good idea and ist my solution the only way this could work?