/ParametricNavigation/googleParametricInclude.txt

http://parametric.googlecode.com/ · Plain Text · 703 lines · 614 code · 89 blank · 0 comment · 0 complexity · 3601a6b8bc3e995adab91ed58ad1fde0 MD5 · raw file

  1. <!-- Meta Tag Cluster code start -->
  2. <script language='javascript'>
  3. // This javascript file is used to setup the meta data cluster view
  4. // The host that the search resides on
  5. var mTGSAHost = "SOMEHOST.com";
  6. var originalURL;
  7. var seperator = ".";
  8. // The name of the id where the meta data clusters are going to be placed
  9. var idName = "";
  10. // Whether or not we are going to show the number of hits beside each item
  11. // By default, displaying the hit count is turned off.
  12. var mTShowNumbers = 0;
  13. // Hashes used for various things such as whether to display or combine fields
  14. // and sorting information.
  15. var mTDisplayHash;
  16. var mTCombineHash;
  17. var mTSortHash;
  18. var mTDisplayNameHash;
  19. var mTArray;
  20. // The header to display above the parametric navigation
  21. var mTHeader = "Parametric Navigation";
  22. // How mata data values do we display for each meta data item before we show the more link and hide the rest
  23. var mTMaxDisplay = 5;
  24. var mTExpandName = "expand...";
  25. var mTCollapseName = "collapse...";
  26. // The label for the all display for each meta data bucket
  27. var mTAllName = "all";
  28. var mTAllLocation = "list"; // Value of list indicates in the list and a value of
  29. // header indicates in the header
  30. // Create a request object
  31. var mTHTTP = mTCreateRequestObject();
  32. // Set the title name
  33. mTSetHeader('Parametric Navigation');
  34. // Set the host name
  35. mTSetHost('gsa41.enterprisedemo-google.com');
  36. // Add the fields that need to be displayed. The format is
  37. // mTAddField(metaTagName, metaTagDelimiter);
  38. mTAddField('keywords', ',');
  39. mTSetDisplayName('keywords', 'Keywords');
  40. mTAddField('techcluster','+');
  41. mTSetDisplayName('techcluster', 'Tech Cluster');
  42. mTAddField('author', '+');
  43. mTSetDisplayName('author', 'Author');
  44. // Set the label and placement for the all link
  45. mTSetAllPlacement('ALL', 'list');
  46. // Set the maximum number of parametric fields to display before
  47. // we display the expand link
  48. mTSetMaxDisplay(5);
  49. // Set the name for the expand and collapse links
  50. mTSetExpandName("more...");
  51. mTSetCollapseName("less...");
  52. // Sort specific fields
  53. // Valid values are 'alpha asc', 'alpha desc', 'hits asc', and 'hits desc'
  54. mTSort('keywords', 'alpha asc');
  55. mTSort('techcluster', 'hits desc');
  56. // Setup any fields that need to be combined. The format is
  57. // mTCombineField(formField, toField);
  58. mTCombineField('creationdate', 'createdate');
  59. // Create the Request Object that we will use to make AJAX calls.
  60. function mTCreateRequestObject()
  61. {
  62. var ro;
  63. var browser = navigator.appName;
  64. if(browser == "Microsoft Internet Explorer")
  65. {
  66. ro = new ActiveXObject("Microsoft.XMLHTTP");
  67. } else
  68. {
  69. ro = new XMLHttpRequest();
  70. }
  71. return ro;
  72. }
  73. // This function allows the user to select the meta data tags that they want to
  74. // display.
  75. function mTAddField(metaTagName, metaTagDelimiter)
  76. {
  77. if (!mTDisplayHash)
  78. {
  79. mTDisplayHash = new Array();
  80. }
  81. mTDisplayHash[metaTagName] = metaTagDelimiter;
  82. }
  83. // This function allows the user to change the display name of the meta tags
  84. // that they are displaying.
  85. function mTSetDisplayName(metaTagName, metaTagDisplayName)
  86. {
  87. if (!mTDisplayNameHash)
  88. {
  89. mTDisplayNameHash = new Array();
  90. }
  91. mTDisplayNameHash[metaTagName] = metaTagDisplayName;
  92. }
  93. // This function allows the user to set the header displayed above the
  94. // parametric navigation
  95. function mTSetHeader(headerName)
  96. {
  97. mTHeader = headerName;
  98. }
  99. // This function allows the user to set the placement and text of the all link
  100. function mTSetAllPlacement(allName, allLocation)
  101. {
  102. mTAllName = allName;
  103. mTAllLocation = allLocation.toLowerCase();
  104. }
  105. // This function allows the user to tell parametric to show or hide the numbers
  106. function mTSetShowNumbers(show)
  107. {
  108. mTShowNumbers = show;
  109. }
  110. // This function allows the user to set name of the value to display for the
  111. // expand... link.
  112. function mTSetExpandName(expandName)
  113. {
  114. mTExpandName = expandName;
  115. }
  116. // This function allows the user to set name of the value to display for the
  117. // collapse... link.
  118. function mTSetCollapseName(collapseName)
  119. {
  120. mTCollapseName = collapseName;
  121. }
  122. // This function allows the user to set the maximum number of items to be
  123. // displayed for each meta tag.
  124. function mTSetMaxDisplay(maxDisplay)
  125. {
  126. mTMaxDisplay = maxDisplay;
  127. }
  128. // This function allows the user to set the host to send the parametric query
  129. // to.
  130. function mTSetHost(hostName)
  131. {
  132. mTGSAHost = hostName;
  133. }
  134. // This function allows the user to set how the parametric results for a
  135. // specific metaTag are sorted.
  136. // A sortBy value of 'alpha asc' indicates alphabetical sorting in ascending order.
  137. // A sortBy value of 'alpha desc' indicates alphabetical sorting in descending order.
  138. // A sortBy value of 'hits asc' indicates sorting on hits in ascending order.
  139. // A sortBy value of 'hits asc' indicates sorting on hits in descending order.
  140. function mTSort(metaTagName, sortBy)
  141. {
  142. if (!mTSortHash)
  143. {
  144. mTSortHash = new Array();
  145. }
  146. mTSortHash[metaTagName] = sortBy;
  147. }
  148. // This function allows the user to select the meta data tags that they want to
  149. // display.
  150. function mTCombineField(mTNameS, mTNameE)
  151. {
  152. if (!mTCombineHash)
  153. {
  154. mTCombineHash = new Array();
  155. }
  156. mTCombineHash[mTNameS] = mTNameE;
  157. }
  158. // This function is called when the page is loaded. This kicks off the calls
  159. // to get all the meta tag values.
  160. function mTLoad(id, mTURL)
  161. {
  162. idName = id;
  163. var partialFields = "";
  164. originalURL = "http://" + mTGSAHost + "/search?" + mTURL;
  165. // Modify the URL to get the appropriate XML output
  166. var url = "http://" + mTGSAHost + "/search?" + mTURL + "&amp;num=100";
  167. url = url.replace(/&amp;proxystylesheet=.*?&amp;/, "&amp;");
  168. // alert("in mtLoad about to post " + url);
  169. // This must be a get or it will not work with firefox. For IE it can be
  170. // either and it will work.
  171. mTHTTP.open('get', url);
  172. mTHTTP.setRequestHeader("Content-Length", url.length);
  173. mTHTTP.onreadystatechange = mTHandleResponse;
  174. mTHTTP.send(null);
  175. }
  176. function mTHandleResponse()
  177. {
  178. if(mTHTTP.readyState == 4)
  179. {
  180. if (mTHTTP.status == 200)
  181. { // perfect!
  182. var response = mTHTTP.responseXML;
  183. // Parse the results and build the appropriate list of meta tags
  184. // and thier count.
  185. mTParse(idName, response);
  186. } else
  187. {
  188. // there was a problem with the request,
  189. // for example the response may be a 404 (Not Found)
  190. // or 500 (Internal Server Error) response codes
  191. alert("HTTP ERROR STATUS: " + mTHTTP.status);
  192. var responseText = mTHTTP.responseText;
  193. alert(responseText);
  194. }
  195. }
  196. }
  197. function trim(str)
  198. {
  199. return str.replace(/\s+/g, " ").replace(/^\s*|\s*$/g,"");
  200. }
  201. function mTParse(idName, response)
  202. {
  203. var metaTagName;
  204. var metaTagValue;
  205. var metaTagDelimiter;
  206. var displayTagName = false;
  207. var mTResult = "";
  208. // Go through each meta tag in the XML response.
  209. var metaTags = response.getElementsByTagName('MT');
  210. // Only display parametric information if there is parametric information to
  211. // display
  212. if (metaTags.length &gt; 0)
  213. {
  214. for(var i=0;i &lt; metaTags.length;i++)
  215. {
  216. metaTagName = "";
  217. metaTagValue = "";
  218. metaTagDelimiter = "";
  219. // Get the meta tag name and modify it if necessary.
  220. metaTagName = metaTags[i].attributes.getNamedItem("N").value;
  221. metaTagName = metaTagName.toLowerCase();
  222. metaTagName = mTDoCombination(metaTagName);
  223. // alert("metaTagName = " + metaTagName);
  224. // Get the meta tag value and modify it if necessary.
  225. metaTagValue = metaTags[i].attributes.getNamedItem("V").value;
  226. metaTagValue = trim(metaTagValue);
  227. // alert("metaTagValue = " + metaTagValue);
  228. displayTagName = false;
  229. if (metaTagValue != "")
  230. {
  231. // Find out if the meta tag name matches one that we are suppossed to
  232. // allow
  233. if (mTDisplayHash)
  234. {
  235. // Here we check the current tag name against the list of valid tag names
  236. displayTagName = false;
  237. for (var mT in mTDisplayHash)
  238. {
  239. if (mT.toLowerCase() == metaTagName.toLowerCase())
  240. {
  241. displayTagName = true;
  242. metaTagDelimiter = mTDisplayHash[mT];
  243. }
  244. }
  245. } else
  246. {
  247. displayTagName = true;
  248. }
  249. // If this occurs, then figure out the delimiter
  250. if (displayTagName == true)
  251. {
  252. if (!mTArray)
  253. {
  254. mTArray = new Array();
  255. }
  256. // Do we have a delimiter? If so, we have to see if we have to split
  257. // this value and do this mulitple times.
  258. if (metaTagDelimiter != "")
  259. {
  260. var newMTValues;
  261. newMTValues = metaTagValue.split(metaTagDelimiter);
  262. for(var j=0;j &lt; newMTValues.length;j++)
  263. {
  264. if (newMTValues[j] != "")
  265. {
  266. // Call a function here which will generate the hash with the
  267. // correct value.
  268. mTArray = mTDoHash(mTArray, metaTagName, newMTValues[j]);
  269. }
  270. }
  271. } else
  272. {
  273. // Call a function here which will generate the hash with the
  274. // correct value.
  275. mTArray = mTDoHash(mTArray, metaTagName, metaTagValue);
  276. }
  277. }
  278. }
  279. }
  280. }
  281. // Output the results to the page
  282. mTOutputParametric(idName);
  283. }
  284. function mTDoHash(mTArray, mTName, mTValue)
  285. {
  286. var lcMTName = mTName.toLowerCase();
  287. var lcMTValue = trim(mTValue.toLowerCase());
  288. if (mTArray[lcMTName])
  289. {
  290. // We have an array for this meta tag. Now let's see if we have a
  291. // dimension for it's value
  292. if (isNaN(mTArray[lcMTName][lcMTValue]))
  293. {
  294. mTArray[lcMTName][lcMTValue] = 1;
  295. } else
  296. {
  297. var tmpVal = mTArray[lcMTName][lcMTValue];
  298. tmpVal++;
  299. mTArray[lcMTName][lcMTValue] = tmpVal;
  300. }
  301. } else
  302. {
  303. mTArray[lcMTName] = new Array();
  304. mTArray[lcMTName][lcMTValue] = 1;
  305. }
  306. return mTArray;
  307. }
  308. function mTDoCombination(mTName)
  309. {
  310. var lcMTName = mTName.toLowerCase();
  311. if (mTCombineHash)
  312. {
  313. if (mTCombineHash[lcMTName])
  314. {
  315. return mTCombineHash[lcMTName];
  316. }
  317. }
  318. return mTName;
  319. }
  320. function mTPosSwitch(mTParametricArr, arrPos1, arrPos2)
  321. {
  322. var tmpArr = new Array();
  323. tmpArr[0] = mTParametricArr[arrPos1][0];
  324. tmpArr[1] = mTParametricArr[arrPos1][1];
  325. mTParametricArr[arrPos1][0] = mTParametricArr[arrPos2][0];
  326. mTParametricArr[arrPos1][1] = mTParametricArr[arrPos2][1];
  327. mTParametricArr[arrPos2][0] = tmpArr[0];
  328. mTParametricArr[arrPos2][1] = tmpArr[1];
  329. return mTParametricArr;
  330. }
  331. function hidediv(pass)
  332. {
  333. var divs = document.getElementsByTagName('div');
  334. for(i=0;i &lt; divs.length;i++)
  335. {
  336. //if they are 'see' divs
  337. if(divs[i].id.match(pass))
  338. {
  339. if (document.getElementById) // DOM3 = IE5, NS6
  340. {
  341. divs[i].style.display="none";// show/hide
  342. } else
  343. {
  344. if (document.layers) // Netscape 4
  345. {
  346. document.layers[divs[i]].display = 'none';
  347. } else // IE 4
  348. {
  349. document.all.hideShow.divs[i].display = 'none';
  350. }
  351. }
  352. }
  353. }
  354. }
  355. function showdiv(pass)
  356. {
  357. var divs = document.getElementsByTagName('div');
  358. for(i=0;i &lt; divs.length;i++)
  359. {
  360. if(divs[i].id.match(pass))
  361. {
  362. if (document.getElementById)
  363. {
  364. divs[i].style.display="block";
  365. } else if (document.layers) // Netscape 4
  366. {
  367. document.layers[divs[i]].display = 'visible';
  368. } else // IE 4
  369. {
  370. document.all.hideShow.divs[i].display = 'block';
  371. }
  372. }
  373. }
  374. }
  375. function mTOutputParametric(idName)
  376. {
  377. var mTResult = "";
  378. if (mTArray)
  379. {
  380. mTResult = "&lt;html&gt;&lt;body&gt;&lt;br/&gt;&lt;h3&gt;" + mTHeader + "&lt;/h3&gt;&lt;font size=\"-1\"&gt;";
  381. for (var i in mTArray)
  382. {
  383. var baseURL = originalURL + "&amp;partialfields=" + i + ":";
  384. if ((mTDisplayNameHash != null) &amp;&amp; (mTDisplayNameHash[i]))
  385. {
  386. mTResult += "&lt;b&gt;" + mTDisplayNameHash[i] + "&lt;/b&gt;";
  387. } else
  388. {
  389. mTResult += "&lt;b&gt;" + i + "&lt;/b&gt;";
  390. }
  391. if (mTAllLocation == "header")
  392. {
  393. mTResult += "(&lt;a href=\"javascript:void(0);\" onClick=\"setCookie('" + i + "', '');var newURL=addPartialFieldsToURL('" + originalURL + "');document.location.href=newURL;\"&gt;" + mTAllName + "&lt;/a&gt;)&lt;br/&gt;";
  394. } else if (mTAllLocation == "list")
  395. {
  396. mTResult += "&lt;br/&gt;&lt;a href=\"javascript:void(0);\" onClick=\"setCookie('" + i + "', '');var newURL=addPartialFieldsToURL('" + originalURL + "');document.location.href=newURL;\"&gt;" + mTAllName + "&lt;/a&gt;&lt;br/&gt;";
  397. }
  398. // Stuff the values for this meta tag in an array
  399. var mTParametricArr = new Array();
  400. var mTParametricCnt = 0;
  401. for (var j in mTArray[i])
  402. {
  403. if (trim(j).length &gt; 0)
  404. {
  405. mTParametricArr[mTParametricCnt] = new Array();
  406. mTParametricArr[mTParametricCnt][0] = j;
  407. mTParametricArr[mTParametricCnt][1] = mTArray[i][j];
  408. mTParametricCnt++;
  409. }
  410. }
  411. // Now we need to sort if this field is one of the ones we need to sort
  412. var sortBy = 0;
  413. var sortOrder = "";
  414. if (mTSortHash)
  415. {
  416. if (mTSortHash[i])
  417. {
  418. var tmpArr = mTSortHash[i].split(/ /);
  419. if (tmpArr[0].toLowerCase() == "hits")
  420. {
  421. sortBy = 1;
  422. }
  423. if (tmpArr[1].toLowerCase() == "asc")
  424. {
  425. sortOrder = "a";
  426. } else if (tmpArr[1].toLowerCase() == "desc")
  427. {
  428. sortOrder = "d";
  429. }
  430. }
  431. }
  432. // We are just using a simple bubble sort here, because the number of
  433. // values in the array doesn't warrant anything more powerful such as a
  434. // quick sort.
  435. if (sortOrder != "")
  436. {
  437. for (var j=0; j &lt; mTParametricArr.length; j++)
  438. {
  439. for (var k=0; k &lt; mTParametricArr.length; k++)
  440. {
  441. if (sortOrder == "a")
  442. {
  443. if (mTParametricArr[j][sortBy] &lt; mTParametricArr[k][sortBy])
  444. {
  445. mtParametricArr = mTPosSwitch(mTParametricArr, j, k);
  446. }
  447. } else if (sortOrder == "d")
  448. {
  449. if (mTParametricArr[j][sortBy] &gt; mTParametricArr[k][sortBy])
  450. {
  451. mtParametricArr = mTPosSwitch(mTParametricArr, j, k);
  452. }
  453. }
  454. }
  455. }
  456. }
  457. // Let's figure out if this has been selected.
  458. var selectedValue = unescape(getCookie(i));
  459. // alert("selectedValue = '" + selectedValue + "'");
  460. // Now print out the information.
  461. for (var j=0; j &lt; mTParametricArr.length; j++)
  462. {
  463. var linkURL = baseURL;
  464. // At this point, we have to determine if there is an ampersand in the
  465. // value. If there is, we have to split based upon it, and search
  466. // multiple partial fields. If not, then we just append the value.
  467. if (mTParametricArr[j][0].indexOf("&amp;") &gt; 0)
  468. {
  469. var tmpPartialFields = mTParametricArr[j][0].split("&amp;");
  470. for(var k=0; k &lt; tmpPartialFields.length; k++)
  471. {
  472. if (k == 0)
  473. {
  474. linkURL += trim(tmpPartialFields[k]);
  475. } else
  476. {
  477. linkURL += seperator + i + ":" + trim(tmpPartialFields[k]);
  478. }
  479. }
  480. } else
  481. {
  482. linkURL += mTParametricArr[j][0];
  483. }
  484. if (j == mTMaxDisplay)
  485. {
  486. mTResult += "&lt;div id=\"" + i + "_expand\"&gt;&lt;a href=\"javascript:void(0)\" onClick=\"hidediv('" + i + "_expand');showdiv('" + i + "_collapse');\">" + mTExpandName + "&lt;/a&gt;&lt;/div&gt;";
  487. mTResult += "&lt;div id=\"" + i + "_collapse\" style=\"display:none\"&gt;";
  488. }
  489. if ((selectedValue != null) &amp;&amp; (selectedValue == mTParametricArr[j][0]))
  490. {
  491. mTResult += "&lt;b&gt;&lt;font color='red'&gt;" + mTParametricArr[j][0] + "&lt;/font&gt;&lt;/b&gt;";
  492. } else
  493. {
  494. mTResult += "&lt;a href=\"javascript:void(0)\" onClick=\"setCookie('" + i + "', '" + mTParametricArr[j][0] + "');var newURL=addPartialFieldsToURL('" + linkURL + "');document.location.href=newURL;\"&gt;" + mTParametricArr[j][0] + "&lt;/a&gt;";
  495. }
  496. if (mTShowNumbers)
  497. {
  498. mTResult += " (" + mTParametricArr[j][1] + ")";
  499. }
  500. mTResult += "<br/>";
  501. }
  502. if (mTParametricArr.length &gt; mTMaxDisplay)
  503. {
  504. mTResult += "&lt;a href=\"javascript:void(0)\" onClick=\"hidediv('" + i + "_collapse');showdiv('" + i + "_expand');\"&gt;" + mTCollapseName + "&lt;/a&gt;&lt;/div&gt;";
  505. }
  506. mTResult += "&lt;br/&gt;&lt;br/&gt;";
  507. }
  508. mTResult += "&lt;/font&gt;&lt;/body&gt;&lt;/html&gt;";
  509. } else
  510. {
  511. mTResult += "<html><body></body></html>";
  512. }
  513. // Output the results to the page
  514. document.getElementById(idName).innerHTML = mTResult;
  515. }
  516. function setCookie (name, value, expires, path, domain, secure)
  517. {
  518. // alert("setting cookie '" + name + "' to value '" + value + "'");
  519. document.cookie = name + "=" + escape(value) +
  520. ((expires) ? "; expires=" + expires : "") +
  521. ((path) ? "; path=" + path : "") +
  522. ((domain) ? "; domain=" + domain : "") +
  523. ((secure) ? "; secure" : "");
  524. }
  525. function getCookie(name)
  526. {
  527. // alert("getting cookie '" + name + "'");
  528. var nameEQ = name + "=";
  529. var ca = document.cookie.split(';');
  530. for(var i=0;i &lt; ca.length;i++)
  531. {
  532. var c = ca[i];
  533. while (c.charAt(0)==' ') c = c.substring(1,c.length);
  534. if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  535. }
  536. return null;
  537. }
  538. function replaceAll(str, replaceFrom, replaceWith )
  539. {
  540. var returnString = str;
  541. while(returnString.match(replaceFrom) != null)
  542. {
  543. returnString = returnString.replace(replaceFrom, replaceWith);
  544. }
  545. return returnString;
  546. }
  547. function removePartialFieldsFromURL(URL)
  548. {
  549. var newURL = URL;
  550. // Get rid of any partialfields that occur in the middle of the URL
  551. if (newURL.match(/&amp;partialfields=.*?&amp;/) != null)
  552. {
  553. while (newURL.match(/&amp;partialfields=.*?&amp;/) != null)
  554. {
  555. newURL = newURL.replace(/&amp;partialfields=.*?&amp;/, "&amp;");
  556. }
  557. }
  558. // Get rid of partialfields that occurs at the end of the URL
  559. newURL = newURL.replace(/&amp;partialfields=.*/, "");
  560. return newURL;
  561. }
  562. function addPartialFieldsToURL(URL)
  563. {
  564. var newURL = removePartialFieldsFromURL(URL);
  565. var ca = document.cookie.split(';');
  566. var pfCount = 0;
  567. for(var i=0;i &lt; ca.length;i++)
  568. {
  569. var c = trim(ca[i]);
  570. // Don't allow for cookies that start with two underscores or that are one
  571. // character.
  572. if (c.match(/^__/) == null)
  573. {
  574. var cookieName = c;
  575. cookieName = cookieName.replace(/\=.*$/, "");
  576. if (cookieName.length &gt; 1)
  577. {
  578. var cookieValue = unescape(getCookie(cookieName));
  579. if ((cookieValue != null) &amp;&amp; (cookieValue != ""))
  580. {
  581. if (pfCount == 0)
  582. {
  583. newURL += "&amp;partialfields=";
  584. } else
  585. {
  586. newURL += seperator;
  587. }
  588. if (cookieValue.indexOf("&amp;") > 0)
  589. {
  590. var tmpPartialFields = cookieValue.split("&amp;");
  591. for(var k=0; k &lt; tmpPartialFields.length; k++)
  592. {
  593. if (k == 0)
  594. {
  595. newURL += escape(cookieName + ":" + escape(trim(tmpPartialFields[k])));
  596. } else
  597. {
  598. newURL += seperator + escape(cookieName + ":" + escape(trim(tmpPartialFields[k])));
  599. }
  600. }
  601. } else
  602. {
  603. newURL += escape(cookieName + ":" + escape(trim(cookieValue)));
  604. }
  605. pfCount++;
  606. }
  607. }
  608. }
  609. }
  610. // alert("newURL = " + newURL);
  611. return newURL;
  612. }
  613. </script>
  614. <!-- Meta Tag Cluster code end -->