I'm trying to create a service in which the user will input some text data, like a blog post or something like that and my service will replace some "special words" in their text for links. for example:
"...Pink Floyd were an English rock band that achieved international success with their progressive and psychedelic rock music..."
"...<a href="http://www.xxx.com?q=pink%20floyd">Pink Floyd</a> were an English <a href="http://www.xxx.com?q=rock%20band">rock band</a> that achieved international success with their progressive and psychedelic rock <a href="http://www.xxx.com?q=music">music<a/>..."
Something like the wikipedia does!
The general algorithm seems to be very simple:
But the problem is that, i'm handling with around 1 million words in my database. I'm using PHP and MySQL for that, by my knowledge PHP is probably not the best tool for text processing.
I'm afraid about the performance, depending of the traffic and the number of requests this algol could be VERY SLOW....
I tried to find another tools or methods to deal with this, i've found a lot of things, but i think none of then is the right tool for the job. I've found mysql full text search, search lucene, sphinx, solr. Correct me if i'm wrong but i think they are not the right tools for this kind of search.
Can someone suggest me how to deal with this properly.
Things to consider:
- The text unfortunately is in portuguese "pt-br", which i think will be a problem.
- It needs to get the full term, in the above exemple it will have to take "rock band" and not split then into "rock" and "band".
- I don't have deeper knowledge in other programming languages, but if this was the case i'm open for other technologies too!
Don't worry about performance in this problem.
You can always:
Also example of code to search stop words in db:
...
$words = strip_tags($origin);
$words = strtolower($words);
// strip anything (symbols, numbers, etc), keep only words
...
$words = explode(' ', $words);
$found = DB::query(Database::SELECT, "SELECT url, word FROM `stop_words` WHERE word IN (".implode(',',$words).")")->execute()->as_array(); // Kohana framework Database module
$patterns = array();
$replacement = array();
foreach($found AS $row)
{
$patterns[] = '/('.$row['word'].')/i';
$replacement[] = '<a href="'.$row['url'].'">$1</a>';
}
$origin = preg_replace($patterns, $replacement, $origin);