Re: Algorithm

From: Date: Mon, 09 Oct 2000 14:12:13 +0000
Subject: Re: Algorithm
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-19191@lists.php.net to get a copy of this message
Hi ! Thanks for all replys. 1 - I know there are many PHP (and Perl regexp) functions to do the job, nut why may I go to re-invent the wheel. I'm sure there are many probed algorithms on the "matrix"... 2 - The code below it's Ok, but is so simple. I need to split more complex expressions like: +dog -terrier "a dog called George Clinton" (It means get all the site having the word dog but not havin the word terrier and with the expression "a dog called George Clinton" or more complex like: +dog -terrier +"a dog called George Clinton" (It means get all the site having the word dog but not havin the word terrier and havin the expression "a dog called George Clinton") I've a delay in my project and don't want to waste time to re-invent the wheel. Thanks in advance. Javier *********** REPLY SEPARATOR *********** On 10/9/2000 at 11:12 AM David Robley wrote: >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 (#19191) next »