From d5002dd355ae0578d62f94553a5fb8607ab74c71 Mon Sep 17 00:00:00 2001 From: John Klehm Date: Mon, 7 Apr 2008 15:27:57 -0500 Subject: matchByVerbAndTerm.php: view that calls into the db index and retrieves objectIds based on request string --- matchByVerbAndTerm.php | 104 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 104 insertions(+), 0 deletions(-) create mode 100644 matchByVerbAndTerm.php diff --git a/matchByVerbAndTerm.php b/matchByVerbAndTerm.php new file mode 100644 index 0000000..d11bebe --- /dev/null +++ b/matchByVerbAndTerm.php @@ -0,0 +1,104 @@ +q_es: $term

\n"; + +$term = nice_url_name($term); + +###DEBUG +#$out .= "

f_es: $term

\n"; +#$out .= "

Verb: $verb Term: $term Hash: " . md5($term) . "

\n"; + +$indexQuery = ''; +switch($verb) +{ + case 'app': + $indexQuery = "SELECT objectId, name, type, rank FROM searchIndex WHERE hash='" . + md5($term) . "' ORDER BY name"; + break; + case 'vendor': + $indexQuery = "SELECT objectId, name, type FROM searchIndex WHERE hash='" . + md5($term) . "' AND type='" . SEARCH_INDEX_TYPE_VENDOR ."'"; + break; + default: + $indexQuery = "SELECT objectId, name, type FROM searchIndex WHERE hash='" . + md5($term) . "'"; +} + + +###DEBUG +#$out .= "

Query: $indexQuery

\n"; + +$noResultsErrorMessage = "

Sorry you entered: $verb/$term and I couldn't find anything to match it.

\n"; +$result = query_appdb($indexQuery, "Get matching object manager ids"); +if ($result) +{ + $matchedObjects = array('objectId' => array(), 'type' => array()); + $numResults = 0; + +###DEBUG +# while ($oRow = query_fetch_object($result)) +# { +# $out .= "Row type: " . "$oRow->type" . " ID: " . $oRow->objectId . "\n"; +# $out .= "objectId" . "\">$oRow->name\n"; +# } + + $numResults = query_num_rows($result); + if ($numResults == 1) + { + $oRow = query_fetch_object($result); + $out = file_get_contents("http://appdb.klehm.net/objectManager.php?sClass=" . + $classStrings[$oRow->type] . "&iId=" . "$oRow->objectId"); + echo $out; + exit(0); + } + else if ($numResults > 1) + { + $out .= "\n"; + + if ($highestRankedMatch->rank > 0) + { + $out = file_get_contents("http://appdb.klehm.net/objectManager.php?sClass=" . + $classStrings[$highestRankedMatch->type] . "&iId=" . "$highestRankedMatch->objectId"); + echo $out; + exit(0); + } + else + { + nice_urls_display($out, "Search Results"); + } + } +} + +if ($out == '') +{ + nice_urls_display($noResultsErrorMessage . $out); +} + +?> -- 1.5.4.5