Re: Algorithm

From: Date: Mon, 09 Oct 2000 00:42:45 +0000
Subject: Re: Algorithm
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-19128@lists.php.net to get a copy of this message
On Mon, 09 Oct 2000, Javier Leyba wrote: > Hi ! > > I'm loocking for an algorithm to split words or phrases from an input field like search > engines do. I mean I need something to interpreter words people put into input fields like > > football +maradona -mexico > > (like Altavista, Google etc.) > > I don't want to invent the wheel and I guess there are many probed algorithms to do the > job. > > Could anybody help me ? > > Thanks in advance. > > Javier This was posted to the list a while back by Ryan Adams <radams@fcs.uga.edu> function search_query ($str, $tablename, $searchfields, $resultfields, $after_where="") { // ryan adams 6/6/00 // $searchfields are space separated: "field1 field2 field3" // $resultfields are comma separated: "field1, field2, field3" // $str is in the form "-nope +yep +thistoo -notthis" // note: each entry must have a + or - before it or it is ignored $a_fields = explode (" ", $searchfields); $a = explode (" ", $str); while (list($k, $v) = each ($a)) { if ($v[0] == "-") { $a_query[] = "NOT LIKE \"%".substr ($v, 1)."%\""; } elseif ($v[0] == "+") { $a_query[] = "LIKE \"%".substr ($v, 1)."%\""; } } for ($i=0; $i<@count($a_fields); $i++) { $naq = ""; for ($j=0; $j<count($a_query); $j++) { $naq[]="$a_fields[$i] $a_query[$j]"; } $b_query[] = "(".implode (" AND ", $naq).")"; } $q = implode (" OR ", $b_query); $q1 = "select $resultfields from $tablename where ($q) "; if ($after_where) $q1 .= $after_where; return $q1; } -- David Robley | WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet | http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA

« previous php.general (#19128) next »