Mike Chambers

code = joy

Challenge : Search engine in 4 lines of code?

with 25 comments

I was just reading this article about the closing of WebMonkey. One of the things they mentioned were “stunt journalism” articles where they would do things such as write chat engines, or search engines in four lines of code.

Hmm… pretty interesting. So, knowing the ingenuity of the Flash community, I thought I would see what you could do. So, lets start off with something easy, can you create a search engine in Flash in 4 lines of code or less? If so, post the code in the comments (you can use any components included with Flash MX 2004 Pro).

Written by mikechambers

February 25th, 2004 at 8:32 pm

Posted in ActionScript

25 Responses to 'Challenge : Search engine in 4 lines of code?'

Subscribe to comments with RSS

  1. searchGoogle = function(what) {
    getURL(“http://www.google.com/search?q=“+what+”&ie=UTF-8&oe=UTF-8&hl=nl&meta=”,”_blank”);
    }
    searchGoogle(“macromedia”);

    OK, this is a pretty lame attempt … great idea though Mike :) Looking forward to seeing what people come up with!

    Peter Elst

    25 Feb 04 at 9:05 pm

  2. 4 lines of codes ? it depend on how many instruction you put in a line

    dvhh

    25 Feb 04 at 11:47 pm

  3. continuing from peter elst’s comment…

    createClassObject(mx.controls.TextInput,’srcPhrase_txt’,0);
    createClassObject(mx.controls.Button,’srcButton_btn’,1);
    srcButton_btn._x = 100;
    srcButton_btn.onRelease = function(){getURL(“href=”http://www.google.com/search?q=“+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}”>http://www.google.com/search?q=“+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}”>http://www.google.com/search?q=“>http://www.google.com/search?q=“+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}”>http://www.google.com/search?q=“>http://www.google.com/search?q=“+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}”>http://www.google.com/search?q=“+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}”>http://www.google.com/search?q=“>http://www.google.com/search?q=“+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}

    yuks

    26 Feb 04 at 1:11 am

  4. whoops that preview thing screwed up my code. take deux…

    createClassObject(mx.controls.TextInput,’srcPhrase_txt’,0);
    createClassObject(mx.controls.Button,’srcButton_btn’,1);
    srcButton_btn._x = 100;
    srcButton_btn.onRelease = function(){getURL(“http://www.google.com/search?q=“+srcPhrase_txt.text+”&ie=UTF-8&oe=UTF-8&meta=”,”_blank”);}

    yuks

    26 Feb 04 at 1:13 am

  5. I wouldnt call opening new Google window “search engine”. Search engine could use Google to search for things, but it would still have to present the result in Flash.

    tonypa

    26 Feb 04 at 5:52 am

  6. You can simply call google through their api if you want to query their search enging and then capture the xml data back in your app.
    About the 4 lines of code… unless it’s just a query forwarding (as the ones above) I don’t other way….

    roskata

    26 Feb 04 at 8:55 am

  7. Boy I would love to have a php script to get thesaurus definitions from Merriam Webster to use in my new TTS flash/shockwave chat bot. Just learning php, and hoping the answer will magically appear here!

    Sally C

    26 Feb 04 at 10:31 am

  8. Even with the Google API and the web service component, I’m over 4 lines just with the html formatting and event listeners. And that’s kind of cheating because the component surely has a few hundred lines. Oh well.

    nick

    26 Feb 04 at 10:52 am

  9. yuks,

    both _x and onRelease can be placed in an object and passed as the 4th parameter in createClassObject, thereby reclaiming 2 lines of code…. maybe? How do yo define a line of code anyway?

    bse

    26 Feb 04 at 3:13 pm

  10. OK, Michael McKellip and myself did a complete flash app google search not just a get URL. There are 2 versions posted one has 3 lines and the other is 4 lines. Both do the searching within flash and only bounce out to the result site when the title is clicked from flash. Download them out at http://www.richtretola.com/google/

    Rich Tretola

    26 Feb 04 at 4:32 pm

  11. function searchForText(text, searchString){
    return text.indexOf(searchString);
    }
    searchForText(“Once upon a time, Utilitarianism was neato.”, “time”);

    1, 2, 3, 4. Do I win?

    JesterXL

    27 Feb 04 at 10:58 am

  12. darron

    1 Mar 04 at 8:45 pm

  13. var result:Number = IF_SearchText_txt.text.indexOf(IF_SearchField_txt.text);
    if (IF_SearchField_txt.text != “” && result>=0) {
    Selection.setFocus(“_root.IF_SearchText_txt”);
    Selection.setSelection(result, result+IF_SearchField_txt.text.length);}

    If you just want to fint the index of the first instance of the searching text then all you need is the first line, the last three just test that the text you are searching for is not empty, then sets focus to the Input text that is holding the text, and then highlights the text.

    IF_SearchField_txt // Input Text Component
    IF_SearchText_txt // Input Text Component

    The code should be invoked by a button, or some other event. change, etc.

    mark

    3 Mar 04 at 5:13 pm

  14. The other option is to use the web services to connect to google. create a data grid component and bind the fields using the Component Inspector. The only code would be for an event to invoke the behavior.

    Mark

    3 Mar 04 at 5:22 pm

  15. TURN YOUR WEBSITE TRAFFIC INTO MONEY
    WE BUY ALL YOUR TRAFFIC

    CLICK HERE TO TURN YOUR WEBSITE TRAFFIC INTO MONEY

  16. Thanks for your great site. I’ll be back soon and check for some updates and more of your great informations. Thanks alot !!
    lecken

    Lecken

    26 Jun 04 at 11:06 am

  17. Good job, i have added your site to my bookmarks!!!

    Emil Lazarian

    29 Jun 04 at 6:02 pm

  18. Why Buy2D?
    –Make what you can NOT afford now be available to you!
    –Instant Software Delivery System;
    –100% Full Retail CD version;
    –100% Full Working.

    Get what you are looking for now!Here you’ll find great Business&Finance,CAD,CAM,CAE,PLM solution software,Mutimedia application,web development software,enterprise solution and more from many of the world’s top software publishers. Our regular prices are guaranteed to be the lowest on the planet!

    No more waiting! Buy any CD, and gain immediate access to the contents online.Download CD images whenever you need them.Save on desk space and shipping charges!

    www.Buy2d.com

    1 Sep 04 at 7:00 am

  19. Hello !!! Great Site !!!

    My new Site

    30 Dec 04 at 10:02 pm

  20. Your site it`s very good! Welcome to my site.

    limousine

    6 Jan 05 at 3:19 pm

  21. Hmm, now that was an interesting post! thanks for sharing. Well, I wish you good luck with your site and keep up the good work!

  22. Great site :)

    Makesolutions

    12 Jan 05 at 4:06 pm

  23. Good site! I find more information on your site.

    Stiven Larson

    21 Jan 05 at 8:53 am

  24. I just read this quote today and I think it’s awesome:

    It is by universal misunderstanding that all agree. For if, by ill luck, people understood each other, they would never agree.

    Charles Baudelaire

    Just thought I’d share.

    Mike

    Online Degree

    23 Jan 05 at 6:28 pm

  25. function search4( arr, str ) {
    var rtn = [];
    for ( var i=0; i<arr.length; i++ ) if ( arr[i].indexOf(str)!==-1 ) rtn.push(arr[i]);
    return rtn;
    }
    var contents_arr = ["the dog and duck", "the fizgig and firkin", "the blue ball", "the double locks", "the exchange"];
    var srch_matches = search4( contents_arr, “and” );
    alert(srch_matches);

    pete

    22 Apr 05 at 10:46 am

Leave a Reply