Compare Search Implementations (v2)

Revision 2 of this benchmark created by Levi Hackwith on


Preparation HTML

<table border="0" cellpadding="5" class="searchResults" width="100%" id = "search-results-table">
        </table>
        <p class="searchDetails" id = "search-details"></p>

Setup

/* Generated with Author-it 6.1.16.22386  10/23/2013 8:54:57 AM */
    Page = new Array();
    Page[0] = new Array("Copyright © 2023 ACME Corporation<br>All rights reserved", "The software and hardware that comprise your ACME&#8482; product contain proprietary information of ACME Corporation; it is provided under a license agreement containing restrictions on use and disclosure and is also protected by copyright law.  Reverse engineering is prohibited.", "Due to continued product development this information may change without notice.  If you find any problems in the documentation, please report them to us in writing.  ACME Corporation does not warrant that this document is error-free.", "Neither ACME Corporation nor its subsidiaries are responsible for accidents or inconveniences that might occur during teleportation.", "No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording or otherwise without the prior written permission of ACME Corporation.", "This document was created using Author-it&#8482; Total Document Creation ", "ACME Corporation<br>PO Box 998787<br>Nassau<br>Bahamas<br><br>Internet E-Mail: support@acmeteleportation.com<br>Website: http://www.acmetelportation.com", "Copyright", "760.htm");
    Page[1] = new Array("Copyright Status: Argentina Government retains a nonexclusive, royalty-free license to publish or reproduce these documents, or allow others to do so, for Argentina Government purposes. These documents may be freely distributed and used for non-commercial, scientific and educational purposes. Commercial use of the documents available from this server may be protected under Argentina and Foreign Copyright Laws. Individual documents on this server may have different copyright conditions, and that will be noted in those documents. ", "Disclaimer of Endorsement: Reference herein to any specific commercial products, process, or service by trade name, trademark, manufacturer, or otherwise, does not necessarily constitute or imply its endorsement, recommendation, or favoring by Argentina Government. The views and opinions of authors expressed herein do not necessarily state or reflect those of Argentina Government, and shall not be used for advertising or product endorsement purposes.", "Disclaimer of Liability: With respect to documents available from ACME Teleportation, neither ACME Teleportation nor any of their employees, makes any warranty, express or implied, including the warranties of merchantability and fitness for a particular purpose, or assumes any legal liability or responsibility for the accuracy, completeness, or usefulness of any information, apparatus, product, or process disclosed, or represents that its use would not infringe privately owned rights. ", "Disclaimer", "750.htm");
    Page[2] = new Array("The nature of teleportation is inherently risky. ACME Corporation and its subsidiaries assume no liability for incidents resulting from misuse of your teleportation device.", "Your Teleportation device will warn you if non-existent coordinates are entered. However, always ensure the accuracy of your target coordinates prior to teleporting. If teleporting to an unfamiliar location check the State Department Website for current travel advisories, as well as the local weather in the target area. ACME Corporation cannot be held responsible for teleportation incidents resulting from miss-entered, incorrect, or ill-advised coordinates.", "If the following occurs while using ACME Teleportation's products: ", "Misplacing of objects (including people, pets or luggage) when using an ACME Teleportation teleportation devices.", "Teleportation to an incorrect pace.", "Collisions between two or more teleporters, Causing merging into one object", "If the persons teleports into object, such as a tree or building wall, causing morphing into the object.", "Any other accidents during teleportation", "ACME Teleportation cannot be held responsible. For more information please phone +64 21 555 2624.", "Important: Do not attempt to use your ACME Teleporter as a time-travel device by resetting the machine's internal clock. This can cause unpredictable results, for which the ACME Company cannot be held responsible.", "Warnings", "603.htm");
    Page[3] = new Array("Teleportation is the fastest growing - not to mention simply the fastest - form of transportation available. And ACME Teleportation Devices make it simple. The whole world is now at your fingertips!", "A whole world awaits you! Why waste another moment?", "Introduction", "763.htm");
    Page[4] = new Array("Acme Teleportation Devices is the largest manufacturer and distributor of teleportation devices in North America. Founded in 2008, Acme has consistently been a leader in innovative, molecular-level transportation alternatives. Our company's founders (Franz Seltzer and Marcia Dreyfus) began their journey towards excellence in organic matter transference in a Palo Alto, California garage. Since then, the company has grown to over 6000 employees with locations worldwide.", "Our Story", "601.htm");
    Page[5] = new Array("First, we are committed to 100% customer satisfaction, and this includes the highest standards in safety. Second, we are committed to creating the best work environment in the world for our employees. Finally, we are committed to contributing to all the communities in which we are located.", "Our Philosophy", "599.htm");
    Page[6] = new Array("Congratulations on making the switch from the world of airports, bus stations, and train terminals to the world of travel. As an ACME customer, it's clear that you know the difference: you would rather spend your valuable time at your destination than making a long journey via an outdated mode of transportation.", "Leave the space shuttle for the Luddites! You've got places to go. Why waste another moment?", "Before using your new ACME Teleporter for the first time, please take a moment to review this brief Getting Started Guide. And remember, no matter where you go, there you are.", "The Exciting World of Teleportation", "619.htm");
    Page[7] = new Array("@<br>Model X1000 &#8211; the world's first wearable personal transporter. The X1000 Personal Teleportation device weighs only 13 pounds and comes with its own padded carrying case (anti-theft system sold separately). Use the X1000 to transport yourself to any location within a 150 mile radius. The X1000 is guaranteed to re-locate you within five yards of your designated target site. Acme's exclusive SurfaceSensor® avoids embarrassing sub-surface re-entry.", "Acme's exclusive SurfaceSensor surface detector uses a state of the art system to detect the surface before re-entry.  ", "X1000 Description", "827.htm");
    Page[8] = new Array("Built-in, rechargeable dilithium crystal battery.", "Impact-resistant housing with air-cushioned inner support struts.", "Instructional DVD included at no extra charge!", "One-year parts and labor guarantee.", "We like to think of this product as ACME's finest. If you are dissatisfied in any way, please return your Teleportation Device to ACME or your nearest reseller to be considered for a full refund.", "X1000 Features", "638.htm");
    Page[9] = new Array("The ACME X1000 meets all safety standards for personal teleportation devices as determined by the National Teleportation Safety Board (NTPSB). All dilithium crystal components are secured in padded compartments with lightweight lead-substitute lining.", "Height:", "42 in/106.7 cm", "Width: ", "25 in/63.5 cm", "Weight: ", "13 lbs/5.9 kg", "Teleportation radius: ", "150 miles", "X1000 Specifications", "831.htm");
    Page[10] = new Array("Installation of ACME products is fast and easy. Please read these instructions all the way through prior to attempting installation. ", "Getting Started", "746.htm");
    Page[11] = new Array("Your ACME Teleporter ships from the factory in a protective bubble to ensure its safe delivery to your front door.", "For best results, follow these guidelines:", "When unpacking your new ACME Teleportation device, take care to avoid knocking the child-safety switch to the ON position.", "Use a small caliber laser to open the protective bubble. Avoid using lasers over 100,000 watts, blowtorches, or explosives.", "As a safety precaution, your ACME Teleportation device is shipped from the factory in the RECEIVE mode. Before removing the device from its protective bubble, ensure that the red &quot;Incoming&quot; light is not flashing. A flashing red light indicates that another ACME Teleporter is communicating coordinates and a user will be arriving at any moment. The protective bubble is designed to intercept such communication and essentially mark it &quot;Return to Sender.&quot; ", "Unpacking Your Teleportation Device", "622.htm");
    Page[12] = new Array("To assemble the X1000", "Open the backpack by unzipping the zipper in the back (between shoulder straps).", "Place the main module (Part A) into the backpack, with the label toward the outer zipper.", "Snap the accessory mount (Part B) on top of the main module.", "Pull the cords through the the color-coded openings that match the cord color.", "To charge your teleporter, plug the blue cord into the wall uplink socket. ", "Assembling Your Teleportation Device", "749.htm");
    Page[13] = new Array("Setting up your Teleporter only takes a few minutes, but it's a crucial part of teleportation if you intend to return to your starting point.", "Setting Up Your X1000", "832.htm");
    Page[14] = new Array("All ACME products come complete with all necessary hardware and software components.  An instructional video is loaded when you install the software. ACME strongly encourages you to view this video prior to making your first trip.", "To load the ACME software:", "Unzip the front compartment on the Teleportation device.", "Release the latch, then fold the keyboard into the down position.", "Push the ACME DVD in the tray and press Close.", "The Installation Wizard automatically starts. Press Next, then follow the onscreen instructions.", "When installation is complete, remove the DVD.", "Place the DVD in the special storage slot next to the battery compartment.", "Note: ACME Corporation recommends that you always carry the installation DVD with your teleportation device. Although infrequent, teleporting through electrical storms has been known to erase the teleportation memory.", "You are now ready to set your home coordinates.", "Installing the Software", "747.htm");
    Page[15] = new Array("Setting your home coordinates requires you to copy the GPS coordinates found on your Locater, and enter them into your new ACME Teleportation Device's memory. Most homes or offices have Locaters attached to each telephone to automatically transmit your location when ordering for pizza delivery or emergency services. ", "To set your home coordinates:", "Unzip the clear plastic window flap on the front of the backpack. You should be able to see the LCD readout through the plastic.", "Press the Set button.", "Enter your home coordinates exactly as they display on your telephone's Locater.", "Press the Accept button. You will have 30 second to cancel.", "Ensure that the coordinates you entered are correct. If so, press the Accept button again.", "To re-enter your coordinates, press the Reject button, and start over.", "When finished, zip the plastic window to protect the LCD readout.", "Setting your Home Coordinates", "589.htm");
    Page[16] = new Array("Prior to making your first trip, register your ACME Teleportation device to help ACME better assist you in the future. You can register on ACME's Website. When you register your ACME Teleportation device, your home coordinates are stored in ACME's database. If your teleporter is lost or stolen, ACME can trace the unit's location. If you move, be sure to update your new home coordinates.", "Registering your Teleporter", "754.htm");
    Page[17] = new Array("PowerMax 100", "Provides 100 hours of operation before recharging.", "PowerMax 200", "Provides 200 hours of operation before recharging.", "PowerMax 500", "Provides 500 hours of operation before recharging.", "Battery Types", "833.htm");
    Page[18] = new Array("To install the new battery:", "Unscrew the battery compartment door.", "Remove the old battery.", "Place the new battery in the compartment, with the positive (+) end up.", "Replace the battery compartment cover.", "If your batteries need replacing often, read the suggestions for conserving battery power.", "Installing a New Battery", "834.htm");
    Page[19] = new Array("To use your ACME Teleportation Device for the first time, you'll simply need to don the pack, set the GPS locator to the desired site and press GO. It's that easy!", "NOTE: ACME strongly recommends that you set your first trip to a nearby location such as another room in your house until you are comfortable the return procedure.", "Your First Trip", "756.htm");
    Page[20] = new Array("The Target Site determines where the teleporter will send you.", "To set the target site:", "1. Open the Locator Box, on the front of the unit.", "2. Enter the coordinates of your destination.", "3. Press Save.", "Setting the Target Site", "755.htm");
    Page[21] = new Array("Complete your ACME Teleportation system with optional ACME accessories. We're always adding state-of-the art subsystems to our product line, to make your teleportation systems best meet your unique needs.", "ACME Accessories", "536.htm");
    Page[22] = new Array("Many customers have asked us to provide a timer module to add to the teleportation unit. Since most watches are automatically set to the local time through their uplink to the atomic clock, it&#8217;s often difficult to know what time zone you&#8217;ve landed in, and how long you&#8217;ve been there..", "The Tele-Timer is designed to help you avoid missing appointments, meals, and oops - even work, while exploring the far reaches of the earth. Simply set the timer before leaving, and when the designated time period has passed you will be notified.", "Manual Operation", "If you set the Tele-Timer to Manual, a buzzer will sound when the allocated time has passed. You can then press the Return button to go to your Return Target Site destination.", "Automatic Operation", "If you&#8217;re likely to lose track of time-and your better judgment-while caught up in the excitement of a new place, you can set the Tele-Timer to Automatic. When the pre-determined amount of time has passed, your teleporter will sound a brief alarm, then automatically return you to your Return Target Site destination.", "Using the ACME Tele-Timer", "550.htm");
    Page[23] = new Array("You can install the Tele-Timer in less than 30 minutes.", "Parts included", "Tele-Timer", "Velcro ", "To install the Tele-Timer:", "Remove the battery from your teleporter.", "Remove the backing paper from one side of the Velcro.", "Stick the Velcro to the outside of the backpack.", "Remove the backing paper from the other side of the Velcro.", "Stick the Tele-Timer to the Velcro adhesive.", "Once your Tele-Timer is installed properly, you can set it to ensure an on-time return trip.", "Installing the Tele-Timer", "556.htm");
    Page[24] = new Array("To set the Tele-Timer for use:", "Open the front door of the Tele-Timer.", "Using the up (é) and down (ê) arrows, set the timer for the exact number of hours and minutes for your trip.", "Press Enter to save.", "Setting the Tele-Timer", "562.htm");
    Page[25] = new Array("Designed especially for the X1000, the Pro-Tekt Case has a padded interior, double-snap latches, and a lock with two keys.", "ACME X1000 Pro-Tekt Case", "565.htm");
    Page[26] = new Array("Designed especially for the X2001, the Pro-Tekt Case has a padded interior, double-snap latches, a lock with two keys, and compartments for spare batteries and other accessories.", "ACME X2001 Pro-Tekt Case", "568.htm");
    Page[27] = new Array("Designed especially for the X5000, the Pro-Tekt Case has a padded interior, double-snap latches, a lock with two keys, and compartments for spare batteries and other accessories. Retractable wheels make moving your X5000 a breeze!", "ACME X5000 Pro-Tekt Case", "569.htm");
    Page[28] = new Array("@<br>Keep the elements out! ", "The ACME Pro-Tekt Cover is made from rip-stop PVC fabric and is 99.9% waterproof. Pro-Tekt Covers slip over your teleportation device quickly&#8212;even in the worst of conditions. Tested in the middle of hurricane season, the Pro-Tekt covers keep your ACME Teleportation device snug and dry, prolonging the life of your teleporter.", "ACME Pro-Tekt Cover", "570.htm");
    Page[29] = new Array("All ACME Teleportation devices have replaceable parts that should be check regularly and replaced when worn.", "An optional ACME Repair Kit is available. Repair Kits are specifically designed for your teleportation device and contain replacements for the most frequently-repaired items. ", "Visit your Authorized ACME Repair Facility for specialized parts and service. Listing can be found at www.acmeteleportation.com.", "Replaceable Parts", "572.htm");
    Page[30] = new Array("Your ACME Teleportation Device uses only the highest quality materials in its construction. Some components, however, wear out with normal use. ACME Repair Kits are lightweight, portable, and available for each type of teleportation device.", "The ACME X1000 Repair Kit includes:", "Zip-Lube for maintaining zippers.", "One ACME AccuWrench&#8482; set for minor adjustments.", "One roll duct tape.", "ACME X1000 Repair Kit", "575.htm");
    Page[31] = new Array("@<br>The ACME Accessories Pack is a must have item for every teleporter. Ensure you never again run out of juice in that war zone or natural disaster.", "Spare battery", "Car charger", "Power socket charger", "Power socket converters", "Personal Computer connections", "ACME X1000 Accessories kit", "576.htm");
    Page[32] = new Array("Your Acme Teleportation Device requires only minimal care to provide years of happy tele-trips.", "Some suggestions to keep you happily 'porting:", "Annual tune-ups will keep all moving parts squeaky clean (as well as squeak-free).", "After teleports into humid or dusty climates, an interim tune-up may be necessary.", "When travelling with your teleporter on traditional transportation such as a plane or shuttle, take your teleporter as a carry-on item to avoid rough handling by baggage-bots.", "Maintenance", "769.htm");
    Page[33] = new Array("Your ACME Teleportation Device uses only the highest quality materials in its construction. Seams that may be exposed to water or dirt are double-sealed, rivets and other fasteners are made of only the highest-grade heat-resistant titanium, and fabric is treated with a patented dirt repellent.", "Routine cleaning, however, is important to keep your ACME product running smoothly. Twice a year (or more if you teleport often to humid or dusty locations):", "Remove any accessories and wipe the connections with clean, dry cloth.", "Wipe off the exterior of your teleportation device.", "Oil all zippers with Zip-Lube® or similar product.", "Keeping Your Teleporter Clean", "770.htm");
    Page[34] = new Array("Let's face it&#8212;the world is a non-stop adventure, but it can also be a messy place.  Tropical jungles, sub-zero temperatures, and scorching heat can cause your ACME Teleportation device to malfunction, and mis-entered coordinates are not always fun.", "To protect your ACME Teleportation Device, use a common household waterproofer such as Spray-Kevlar® or Force-Field in a Can&#8482; to keep the outside.... outside. ", "The ACME Pro-Tekt Cover provides full coverage for your Teleportation device, and is customized to precisely fit your model. ACME Pro-Tekt Covers are available directly from ACME or from your nearest reseller.", "Protecting Against the Elements", "615.htm");
    Page[35] = new Array("All ACME Teleportation devices have replaceable parts that should be check regularly and replaced when worn.", "An optional ACME Repair Kit is available. Repair Kits are specifically designed for your teleportation device and contain replacements for the most frequently-repaired items. ", "Visit your Authorized ACME Repair Facility for specialized parts and service. Listing can be found at www.acmeteleportation.com.", "Replaceable Parts", "572_1.htm");
    Page[36] = new Array("Authorizes repair facilities are available world wide and designed by the ACME Teleportation &#8482; label in the window.", "Authorized Repair Shops", "586.htm");
    Page[37] = new Array("Occasionally you may encounter unexpected issues with your ACME teleportation device. While these occurrences are rarely cause for alarm, they can be disconcerting. If you take some time to familiarize yourself with this section and follow some basic problem-solving procedures, you'll be prepared for most any circumstance.", "Troubleshooting", "757.htm");
    Page[38] = new Array("Teleportation is one of the safest methods of travel, due to the unlikelihood of intra-molecular collisions. However, a few simple precautions are necessary.", "Always double-check to ensure that your travelling companions have adequate battery power before making a multi-user trip. ", "Check (and re-check) destination coordinates prior to teleporting.", "Avoid &quot;piggy-backing&quot;&#8212;transporting two people with a single-user teleporter&#8212;if the combined weight exceeds 500 lbs/227 kg.", "Before teleporting, ensure that all straps, buckles, zippers or other fasteners are completely closed. ", "Do not attach unapproved accessories or other items to your Teleportation device.", "Tips for Trouble-Free Teleportation", "758.htm");
    Page[39] = new Array("Ensure a long healthy life for your ACME Teleportation Device's batteries! Just remember these tips:", "Keep the batteries out of direct magnetic fields", "After spending time in humid climates, remove your battery and wipe off any built up condensation", "Conserving Battery Power", "775.htm");
    Page[40] = new Array("If a problem occurs during any phase of teleportation, check the following:", "Is my teleporter properly charged?", "Is the child-safety switch set to &quot;OFF&quot;?", "Is my destination site in a country or city-state with a password-activated security shield? ", "Is my passport chip up-to-date and properly implanted?", "Problem Solving", "613.htm");
    Page[41] = new Array("Kevlar is the DuPont Company's brand name for a particular light but very strong synthetic fibere. Kevlar was first used commercially in the early 1970s. It can be spun into ropes or sheets of fabric that can either be used as-is, or used in the construction of composite components. Kevlar is now used in a wide range of applications, from bicycles to body armor, due to its high strength-to-weight ratio.", "Kevlar", "836.htm#o846");
    Page[42] = new Array("A homing device attached to most phone lines to identify the coordinates for the location. Used most commonly in teleportation, emergencies, and pizza delivery.", "Locator Box", "836.htm#o839");
    Page[43] = new Array("ACME's approved storage and travel case for your teleportation device.", "Pro-Tekt Case", "836.htm#o845");
    Page[44] = new Array("ACME's approved home storage facility for your teleportation device.", "Storage-Cells", "836.htm#o843");
    Page[45] = new Array("The process of relocating matter to another place via radio waves.", "Teleportation", "836.htm#o844");
    Page[46] = new Array("An ACME product used to transmit human matter over distances.", "Teleportation Device", "836.htm#o841");
    var PageCount = 47;
    
    
    
    /*----------------------------------------------------------------------*/
    
    
    function highlightSearchResultsOnPage(results, pageIndex, searchWord) {
      "use strict";
    
      var book = Page, // Redefining page variable as book for clarity
        bookPage = book[pageIndex],
        // Page <-- Declared externally, this is what is looped through and searched
        numParagraphs = bookPage.length,
        maxResultTextLength = 350,
        pageFileName = bookPage[numParagraphs - 1], // The last item in the array is always the file name
        pageTitle = bookPage[numParagraphs - 2], // The second-to-last item in the array is always the page title
        bookPageText = bookPage[0], // Remove the page title and page file name from the text and merge paragraphs together
        wordPosition = bookPageText.toLowerCase().indexOf(searchWord),
        matchedWord = "",
        proceedingCharacter = "",
        wordPositionAtSentenceStart = false;
    
      if (results.rowHTML === undefined) {
        results.rowHTML = "";
      }
    
      if (results.numResults === undefined) {
        results.numResults = 0;
      }
    
      if (wordPosition === -1) {
        return;
      }
    
      results.numResults += 1;
      matchedWord = bookPageText.substr(wordPosition, searchWord.length);
      proceedingCharacter = bookPageText.charAt(wordPosition - 2);
      wordPositionAtSentenceStart = (proceedingCharacter === '.' || proceedingCharacter === "") ? true : false;
    
      results.rowHTML += "<tr><td>";
    
      results.rowHTML += "<p>"; // Output HTML for link header
      results.rowHTML += '<a target = "BODY" href = "' + pageFileName + '?partial=true&terms=' + searchWord + '">';
      results.rowHTML += pageTitle;
      results.rowHTML += "</a>";
      results.rowHTML += "</p>";
    
      results.rowHTML += "<p>"; // Output HTML for body text
      if (wordPositionAtSentenceStart === false) { // Don't append ellipsis if the word is at the start of a sentence.
        results.rowHTML += "...";
      }
      results.rowHTML += bookPageText.substr(wordPosition, maxResultTextLength).replace(matchedWord, "<strong>" + matchedWord + "</strong>");
    
      if (wordPosition + maxResultTextLength < bookPageText.length) {
        results.rowHTML += "...";
      }
      results.rowHTML += "</p>";
    
      results.rowHTML += "</tr></td>";
    }
    
    /**
     * Searches the pages of the website (book) and appends the results specific elements on the page
     * @param {string} The word to search for
     */
    
    function searchNew(searchWord) {
      'use strict';
    
      var numLoopIterations,
        // PageCount <-- Declared externally, this is the total number of indexes in Page
        results = {
          rowHTML: "",
          numResults: 0
        };
      PageCount = Page.length - 1; // Subtract one to match actual index range
      if (searchWord.length >= 1) {
        searchWord = searchWord
          .toLowerCase()
          .replace(/&/g, "&amp;") // &
        .replace(/</g, "&lt;") // <
        .replace(/>/g, "&gt;") // >
        .replace(/"/g, "&quot;"); // "
    
        numLoopIterations = (PageCount % 10);
    
        while (numLoopIterations > 0) {
          highlightSearchResultsOnPage(results, PageCount--, searchWord);
          numLoopIterations--;
        }
    
        numLoopIterations = Math.floor(PageCount / 10);
    
    
        while (numLoopIterations > 0) { // Use a modified version of Duff's Device to process large amounts of pages
          highlightSearchResultsOnPage(results, PageCount--, searchWord);
          highlightSearchResultsOnPage(results, PageCount--, searchWord);
          highlightSearchResultsOnPage(results, PageCount--, searchWord);
          highlightSearchResultsOnPage(results, PageCount--, searchWord);
          highlightSearchResultsOnPage(results, PageCount--, searchWord);
          highlightSearchResultsOnPage(results, PageCount--, searchWord);
          highlightSearchResultsOnPage(results, PageCount--, searchWord);
          highlightSearchResultsOnPage(results, PageCount--, searchWord);
          highlightSearchResultsOnPage(results, PageCount--, searchWord);
          highlightSearchResultsOnPage(results, PageCount--, searchWord);
    
          numLoopIterations--;
        }
        document.getElementById("search-results-table").innerHTML = results.rowHTML;
        document.getElementById("search-details").innerHTML = "&nbsp;" + results.numResults + " result(s) found";
    
      }
    }
    /*------------------------------------------------------------------------------------------------------------------------------*/
    
    
    
    /*------------------- BEGIN OLD METHOD -----------------------------------------------------------------------------------------*/
    function search(SearchWord) {
      var Result = "";
      var NrRes = 0;
      if (SearchWord.length >= 1) {
        while (SearchWord.indexOf("<") > -1 || SearchWord.indexOf(">") > -1 || SearchWord.indexOf('"') > -1) {
          SearchWord = SearchWord.replace("<", "&lt;").replace(">", "&gt;").replace('"', "&quot;");
        }
      }
      if (SearchWord.length >= 1) {
        SearchWord = SearchWord.toLowerCase();
        this.status = "Searching, please wait...";
        for (j = 0; j < PageCount; j++) {
          k = Page[j].length - 1;
          for (i = 0; i < k; i++) {
            WordPos = Page[j][i].toLowerCase().indexOf(SearchWord);
            if (WordPos > -1) {
              FoundWord = Page[j][i].substr(WordPos, SearchWord.length);
              NrRes++;
              Result += "<tr><td>";
              Result += "<a target='BODY' href='" + Page[j][k] + "'>" + Page[j][k - 1].replace(FoundWord, FoundWord.bold()) + "</a><br/>\n";
    
              if (i < k - 1) {
                if (Page[j][i].length > 350) {
                  Result += "..." + Page[j][i].substr(WordPos - 100, 200 + FoundWord.length).replace(FoundWord, FoundWord.bold()) + "...\n";
                } else {
                  Result += Page[j][i].replace(FoundWord, FoundWord.bold()) + "\n";
                }
              }
              Result += "</td></tr>";
              break;
            }
          }
        }
      }
    }

Test runner

Ready to run.

Testing in
TestOps/sec
New Way
searchNew('home');
ready
Old Way
search('home');
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 2: published by Levi Hackwith on