Predictive Text...

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Predictive Text...

Post by Klaus » Thu Mar 13, 2025 9:10 am

dunbarx wrote:
Wed Mar 12, 2025 6:26 pm
...
Filter is still slightly faster. Mine also is not limited to the beginning chars in a line, rather it "finds chars"...
Yes, that is nice, but in a "real life" situation like e.g. entering an url in a browser, the user does exspect to find
the character at the the beginning of a line!

Imagine you enter "Do" (to get Dog or whatever...), then you will not exspect to see "WeirDo" in the field. :-D

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Predictive Text...

Post by dunbarx » Thu Mar 13, 2025 5:05 pm

Klaus.
Imagine you enter "Do" (to get Dog or whatever...), then you will not exspect to see "WeirDo" in the field
I disagree. I often try to find text in a dataSet where a string in the middle of a word (or words) in that dataset is where my target lies. Of course this can easily be selected as an option, which harkens back to my first post where I said massive enhancements are likely necessary to the basic "find" methods.

If you are correct about the backSpace thing, doable, of course, but why would anyone making char-by-char entries in one field, watching successive results appear in another field, suddenly select the entire search text and then use the backSpace key to delete only one character??

Such a person deserves to have all his entry data deleted!!

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Predictive Text...

Post by dunbarx » Thu Mar 13, 2025 5:25 pm

Klaus.

At first I though "WeirDo" was German, since I know that capital letters appear in the middle of text now and then.

In nouns?

Anyway, who are you calling a weirdo??

Craig

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Predictive Text...

Post by Klaus » Thu Mar 13, 2025 5:55 pm

dunbarx wrote:
Thu Mar 13, 2025 5:05 pm
Klaus.
Imagine you enter "Do" (to get Dog or whatever...), then you will not exspect to see "WeirDo" in the field
I disagree. I often try to find text in a dataSet where a string in the middle of a word (or words) in that dataset is where my target lies. Of course this can easily be selected as an option, which harkens back to my first post where I said massive enhancements are likely necessary to the basic "find" methods.

If you are correct about the backSpace thing, doable, of course, but why would anyone making char-by-char entries in one field, watching successive results appear in another field, suddenly select the entire search text and then use the backSpace key to delete only one character??

Such a person deserves to have all his entry data deleted!!

Craig
Yes, true, but I thought in this special case only of entering an URL in the browser
And I AM in fact correct about the backSpace thing in my scipt/example stack. 8)
i always test my thing before I post them here.
dunbarx wrote:
Thu Mar 13, 2025 5:25 pm
Klaus.
At first I though "WeirDo" was German, since I know that capital letters appear in the middle of text now and then.
In nouns?
No, "weirdo" is english/american to the bone! :-)
And there a no nouns I know that have capital letters in the middle of them now and then.
dunbarx wrote:
Thu Mar 13, 2025 5:25 pm
Anyway, who are you calling a weirdo??
If the shoe fits, wear it! :D
Come on, Craig, that was just a funny example and no offence whatsoever.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Predictive Text...

Post by FourthWorld » Thu Mar 13, 2025 7:25 pm

dunbarx wrote:
Wed Mar 12, 2025 5:26 pm
Klaus

I wanted to see if the filter version that you posted was faster than the loop version I did. It is, but not by much. I tried a dataSet with 500,000 lines. For each letter typed, my version took 0.9 seconds to find all hits and the filter version took 0.6 seconds.
How did you measure that? I downloaded your stack (can't resist an optimization puzzle), but I saw no automated testing option, only ways to use it interactively.

Also, the stack is titled "Binary Search" but the algo is a loop. Is there another version with a binary search algo?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Predictive Text...

Post by FourthWorld » Thu Mar 13, 2025 7:26 pm

cmhjon wrote:
Mon Mar 10, 2025 1:39 pm
I’d like my app to display a list of possible customers as the user types the name of the customer.
How is the list of customer names obtained?

And what is a reasonable maximum number of names expected to be in that list?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Predictive Text...

Post by FourthWorld » Thu Mar 13, 2025 7:38 pm

Useful bookmark to keep handy - data sets of fictitious customers in varying sizes and formats:
https://dlptest.com/sample-data/namedobemail/
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Predictive Text...

Post by FourthWorld » Thu Mar 13, 2025 8:03 pm

dunbarx wrote:
Thu Mar 13, 2025 5:05 pm
Klaus.
Imagine you enter "Do" (to get Dog or whatever...), then you will not exspect to see "WeirDo" in the field
I disagree. I often try to find text in a dataSet where a string in the middle of a word (or words) in that dataset is where my target lies. Of course this can easily be selected as an option...
Both is probably the best solution. Testing in a browser shows substring results rather than auto-completion results, but there are good use cases for both.

This option can be supported easily with filter by putting an asterisk on both sides of the filter term.

Apparent duplicates may or may not be relevant. There might actually be multiple people in a data set with the same name, and that may be useful to know. To distinguish whether that's useful would require that we know what the search does with what it finds.

Another consideration which may not be possible to address here depending on the particulars of the source data, but browsers usually rank results. Searching for "Richard Dawkins" is probably more interesting to more people than searching for "Richard Gaskin".
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Predictive Text...

Post by dunbarx » Thu Mar 13, 2025 8:15 pm

KLAUS!!!!

Do you, after ALL we have been through together, REALLY think I might have been miffed? :o

Craig

cmhjon
Posts: 190
Joined: Tue Aug 04, 2015 11:55 am

Re: Predictive Text...

Post by cmhjon » Thu Mar 13, 2025 8:33 pm

Hi everyone,

Let me see if I can answer everyone’s questions:

@Dunbarx - when I selected all the text that was in the text field, I wanted to be able to press the delete key (backspaceKey in LC) in order to clear the contents of the field. Adding the few lines of code Klaus suggested resolved that issue.

@FourthWorld - the list of customers will come my MIS/CRM software. The list currently contains 1435 customers.

I also made one additional change to the code:

Code: Select all

filter tList with ("*" & tLookupString & "*")
I added a * before the variable so that if I were looking for “The Acme Widget Company”, I can just type “Acme” and it would show in the list. Without the preceding *, I would have to type “The” to get it to appear in the list.

Now for the next challenge. Suppose the customer name field is populated but I need to add a word to it. For example, the field contains, “The Acme Company” but I need to add “Widget” in between “Acme” and “Company”. If I try to type “Widget” where indicated, because of how the code is written, the cursor keeps moving to the end of the field. I am aware I can fix this by updating the customer list field but that would require a re-compilation and deployment of the updated app. Although I may look into putting the list of customers into a text file on an internal network share and pull from that, any ideas on how to achieve this in the meantime?

Thank you again and best regards,
Jon :-)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Predictive Text...

Post by dunbarx » Thu Mar 13, 2025 8:48 pm

Richard.
How did you measure that?
I made a timer in the usual way, ticks at the end - ticks at the beginning. The really odd thing was that in an earlier version, just visually, the filter method was noticeably faster than the "repeat for..." method. It was only after I changed a few things, nothing pertinent, in my opinion, that they were so close that I decided to time them.

With 550,000 lines of ten-character random words, each keypress through the loop method takes ten ticks to display the results, while each pass through the filter method takes five,

Each is more than acceptable. I suppose filter is more modern.

Loop is shorter, and catches all strings. So there. :wink:

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Predictive Text...

Post by dunbarx » Thu Mar 13, 2025 9:08 pm

cmhjon

Ahem. My old-fashioned loop method already catches any string you type, anywhere in the dataSet, not limited to only the beginning of lines. in any case, whichever method you actually use, I think this is the better way to search.

As for your latest challenge, examine this handler, placed perhaps in a new button. It is used once you have located the single result you were looking for:

Code: Select all

on mouseUp
   get fld "results"
   find it in fld 1 --the dataSet field
   put word 2 of the foundLine into tLine
   put the value of the foundLine into tText
   ask "modify" with tText
   put it into line tLine of fld 1
end mouseUp
I hope you are reading and understanding all the submissions presented in this thread. These "find"-related functions harken back to Hypercard in 1987.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Predictive Text...

Post by dunbarx » Thu Mar 13, 2025 9:13 pm

cmhjon.

Instead of using another button to modify the line found, you could trap 65293 (carriage return) in a rawKeyUp handler, or any other control-style key of your choice, perhaps a function key.

Craig

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Predictive Text...

Post by Klaus » Thu Mar 13, 2025 9:21 pm

dunbarx wrote:
Thu Mar 13, 2025 8:15 pm
KLAUS!!!!
Do you, after ALL we have been through together, REALLY think I might have been miffed? :o
Craig
CRAIG!
No! :-D

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Predictive Text...

Post by FourthWorld » Fri Mar 14, 2025 3:32 am

Here's a comparative benchmark of looping vs filter. Also includes an example of using the filter in a practical UI as described in the OP (the test requirements impose complexity not needed in production).

Highlights for those who may not want to bother downloading it:

- The source list used for testing contains 30,000 names, with a good many duplicates.

- The benchmark runs 10 queries of different search strings, four of which are not in the source text.

- Since the filter command is effectively a loop but one that runs in compiled machine code, it averages about 6 times faster. It would likely be even faster were it not for the embedded regex subsystem that offers so much flexibility for other uses which might need for other tasks.

-Using the textChanged message as the event trigger allows all character entry, deletion, and even drag-n-drop. It's become my go-to trigger for text-change event handling since it was introduced a few years back.
Attachments
Type Search.livecode.zip
(8.12 KiB) Downloaded 273 times
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply