Google search algorithm

FlexibleLearning at aol.com FlexibleLearning at aol.com
Tue Mar 21 12:16:01 CST 2006


AIM:
To permit the use of + (optional) and - to indicate strings that  must or 
must not be included in a search routine.
 
 
Okay, my gauntlet starter bid for 10...
 
THIS SUBMISSION LIMITATION:
Quoted strings are not supported for 'whole matches'.
 
on doSearch
put fld "Search" into tPattern
repeat with  n=1 to num of cds
put (fld "code" of cd n && fld  "Description" of cd n) into tTxt    
if (tPattern="") OR googleMatch(tPattern, tTxt)  then
put (fld "Description" of cd n  &TAB& the id of cd n) &CR after tResult
end if    
end repeat
set the text of  fld "SearchResults" to char 1 to -2 of tResult
end doSearch

function googleMatch tPattern,tTxt
# NOTE: To match a + or -, use  ++ or +-, or -+ or --
repeat for each word W in  tPattern
if W="+" or W="-" then return  TRUE
--
if ("-" is char 1 of W) and  (char 2 to -1 of W is in tTxt) then return FALSE
if ("-"  is char 1 of W) and (char 2 to -1 of W is NOT in tTxt) then next  
repeat
--
if ("+" is char 1 of W)  and (char 2 to -1 of W is NOT in tTxt) then return 
FALSE
if ("+" is char 1 of W) and (char 2 to -1 of W is in tTxt) then next  repeat
--
if W is in tTxt then next  repeat
else return FALSE
end repeat
return TRUE
end googleMatch
 
/H


More information about the metacard mailing list