From 969a49426f0c6716076915fc301020170d1631fa Mon Sep 17 00:00:00 2001 From: John Klehm Date: Mon, 7 Apr 2008 15:25:47 -0500 Subject: runIndexer.php: Script that indexes existing database --- runIndexer.php | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 144 insertions(+), 0 deletions(-) create mode 100644 runIndexer.php diff --git a/runIndexer.php b/runIndexer.php new file mode 100644 index 0000000..aefec27 --- /dev/null +++ b/runIndexer.php @@ -0,0 +1,144 @@ +appName); + return "('" . md5($name) . "'," . + "$oRow->appId," . + SEARCH_INDEX_TYPE_APP . "," . + "'$cleanAppName'," . + "$rank),"; +} + +function hashFrontToBack($name, $nameLen, $oRow) +{ + $tempIndexValues = ""; + for($i = 0; $i < $nameLen;) + { + #skip to separator + while (($name[$i++] != '-') && ($i < $nameLen)); + if ($i < $nameLen) + { + $partName = substr($name, $i,$nameLen-$i); + $out .= "

Part name: $partName

\n"; + + $tempIndexValues .= createInsertString($partName, $oRow, 0); + } + } + + return $tempIndexValues; +} + +function hashBackToFront($name, $nameLen, $oRow) +{ + $tempIndexValues = ""; + for($i = $nameLen; $i > 0;) + { + #skip to separator + while (($name[--$i] != '-') && ($i > 0)); + if ($i > 0) + { + $partName = substr($name, 0, $i); + $out .= "

Part name: $partName

\n"; + + $tempIndexValues .= createInsertString($partName, $oRow, 0); + } + } + + return $tempIndexValues; +} + +function appFamilyQuery($idStart,$idEnd) +{ + return 'SELECT appId, appName, keywords FROM appFamily WHERE state = \'accepted\' AND appId >= ' . + $idStart . ' AND appId < ' . $idEnd; +} + + + +#1000 inserts at a time works +#$vendorQuery = 'SELECT vendorId, vendorName FROM vendor WHERE vendorId >= ' . +# $queryId . ' AND vendorId < '; +#$appVersionQuery = 'SELECT versionId, versionName FROM appVersion WHERE versionId >= ' . +# $queryId. ' AND versionId < '; +#$vendorQuery .= $queryId; +#$appVersionQuery .= $queryId; + +$queryId = 0; +$maxQueryId = 0; +if ($oMax = query_fetch_object(query_appdb('SELECT MAX(appId) AS max from appFamily',"Find highest app id"))) +{ + $maxQueryId = $oMax->max; +} +else +{ + $out .= "Could not find max id from table."; +} + +while ($result = query_appdb(appFamilyQuery($queryId,($queryId += APPDB_MYSQL_MAX_INSERTS_PER_QUERY)),"")) +{ + $indexValues = ""; + while ($oRow = query_fetch_object($result)) + { + $out .= "

======================================

\n"; + $out .= "

Name: $oRow->appName

\n"; + + # store the exact match + $goodName = nice_url_name($oRow->appName); + $out .= "

Good Name: $goodName

\n"; + + // direct hit on name should have highest ranked hash + $indexValues .= createInsertString($goodName, $oRow, APPDB_SEARCH_INDEX_MAX_RANK); + + # chop up the exact matching teram and hash the pieces + $gNameLen = strlen($goodName); + + # drop terms from front to back, cool-edit-pro => edit-pro => pro + $indexValues .= hashFrontToBack($goodName, $gNameLen, $oRow); + + # drop terms from back to front, cool-edit-pro -> cool-edit => cool + $indexValues .= hashBackToFront($goodName, $gNameLen, $oRow); + + # TODO: hash mixed terms, keywords?? + } + + if ($indexValues != "") + { + $indexValLastCharPos = strlen($indexValues) - 1; + if ($indexValues[$indexValLastCharPos] == ',') + { + $indexValues = substr($indexValues, 0, $indexValLastCharPos); + } + + $out .= "

index values: $indexValues

\n"; + if (APPDB_ENABLE_NICE_URLS_INDEXER) + { + if(query_appdb("INSERT INTO searchIndex (hash, objectId, type, name, rank)". + " VALUES $indexValues", "Index data for appdb")) + { + $out .= "

Indexer Query Success

\n"; + } + else + { + $out .= "

Indexer Query Fail

\n"; + } + } + else + { + $out .= "

Indexer off.

\n"; + } + } + + if ($queryId > $maxQueryId) + { + break; + } +} + +nice_urls_display($out, "AppDB: Nice URLs Indexer"); +?> -- 1.5.4.5