Hello Monks

I have a small TK GUI with an Entry field and a Table to display results. I am trying to implement what I call a "progressive search": at every keyboard stroke the database query is performed. As the query string is getting longer, the number of matches are reduced at any new keyboard stroke. I am using the following approach:

$EntryQuery->idletasks;#$EntryQuery is the Tk widget where the user is + typing $SearchField->bind("<Key>", sub { print "Searching for $QueryInput\n";#$QueryInput is a variable + linked with the Entry widget my $ResultsFinal=QueryDatabase($QueryInput); DeleteAllRowsInTable(); PrintingResultsInTable($ResultsFinal); });
Everything works fine... except that, if the subrutines take too long time to be processed, same "query string" (which is progressively getting longer) is searched at the very end of the process. If I search for the word "paragraph", for instance, typing one character after the other, I may get:

Searching for p Searching for pa Searching for par Searching for paragr Searching for paragra Searching for paragrap Searching for paragraph Searching for para # this should have been searched as 4th iteration, +or skipped as no more interesting (since the user has typed another l +etcharacterter) Searching for parag # this should have been searched as 5th iteration, + or skipped as no more interesting (since the user has typed another +character)

As you can imagine, in this way (if the user is typing quicker than the computer is able to process the subrutines), the user ends up with the results matching "parag" instead of "paragraph". Note that the performed subrutines (especially QueryDatabase) are very complex and may require some time to be processed.

What approach could I use to avoid this problem? I was thinking about breaking out of the sequence of the processed subrutines if the user is typing the next character (as this query is no interesting anymore). But I am not sure if this is a good approach. And if yes, which is the best method to achieve it? Thanks for any suggestions


In reply to Tk progressive search by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.