Welcome to WebmasterWorld Guest from 54.167.83.224

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

anyone know how wikipedia does string matches on all it's terms

     
10:06 am on Dec 1, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:July 24, 2002
posts:1124
votes: 0


hi,

i have to implement a string match involving persons names. we have a database of 5,000 names. these have to be detected in short paragraphs.

obviously i'd rather not loop through each line comparing 5000 entries ;)

does anyone have any experience with this or know how wikipedia do it?

many thanks
5:55 pm on Dec 1, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:July 24, 2002
posts:1124
votes: 0


well, i thought why not try it anyway... and it only takes microseconds to parse the 5000 names and preg_match:


foreach ($arr_names as $ID => $name)
{
if (preg_match('/(' . $name . ')\b/i', $_POST['str'], $matches))
{
$m[] = $matches[1];
}
}


(please don't try this with a wikipedia database of 10 million terms lol)
6:30 pm on Dec 1, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 12, 2005
posts:5966
votes: 0


If I had to guess I'm sure Wikipedia must limits the domain of words it selects from by subject matter (or some other meta data) for that particular article. Also, I'm sure they have some type of caching mechanism built in.

You should only need to do this find/replace when either the string changes or the names domain changes; in both cases, you only need to search what has changed (the new names or the new text) if you've already searched the text before. Timestamps on the "names" table should be able to aid in this.