Problem with searching an array[Solved]

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

Post Reply
atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Problem with searching an array[Solved]

Post by atout66 » Fri Feb 20, 2015 9:01 pm

Hi to all,

I encouter a problem when using the script provided in the lesson: How do I Search an Array?
Here:http://lessons.runrev.com/s/lessons/m/4 ... h-an-array
The function <function logarithmicSearch > work fine except it doesn't care for accentueted letters and for sign like "-".
For example a search in the list below will return good results for the words : <Aarhus,abaca,abaissa,abandonnas,enfer>
<à-pic,à-propos,Aarhus,abaca,abaissa,abandonnas,électricité,enfer>
But <à-pic,à-propos,électricité> won't be found.
I put the liste like that for the forum, but in fact it's an array, like in the example of the lesson.
I just add in the script of the function the following line:

Code: Select all

set the caseSensitive to TRUE
but it doesn't change anything.
The array is already sorted correctly.

Any idea or advice will be much appreciated.
J-P.
Last edited by atout66 on Mon Feb 23, 2015 6:26 pm, edited 1 time in total.
Discovering LiveCode Community 6.5.2.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: Problem with searching an array

Post by bn » Sat Feb 21, 2015 6:25 pm

Hi J-P,

the problem is that logarithmicSearch only works on _SORTED_ data. And it does only an ASCII compare. Now the accented characters have a high ASCII value and logarithmicSearch gets confused when it does
if (pArray[tIndex]) > ( pItem )

it is on the wrong track and does not find the right entry.

There is no cure for that really.

What you can do to see that it works when sorted correctly then you could do this:

Code: Select all

on mouseUp
   put "à-pic,à-propos,Aarhus,abaca,abaissa,abandonnas,électricité,enferà-pic,à-propos,Åarhus,abaca,abaissa,abandonnas,électricité,enfer" into tArray
   sort items of tArray ascending
   set the wholeMatches to true
   put itemOffset("à-pic",tArray) into tItemNo
   put item tItemNo of tArray into tSearch
   
   split tArray by comma
   put tArray into tArray2
   
   put logarithmicSearch (tArray,tSearch, 0, 15) into tArrayKeyLog
   
   put  "logSearch:" && "itemNumber:" && tArrayKeyLog && "content:" && tArray2[tArrayKeyLog] 
end mouseUp
Now you have the list sorted correctly according to the ascii values of the items but the order is not what you entered.

I have no idea at the moment how to cure this.
Kind regards

Bernd

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: Problem with searching an array

Post by atout66 » Sat Feb 21, 2015 8:00 pm

Thanks Bernd, that's pretty cleaver the way you split the data. I understand better the way it works.
From your advice I've got it to work fine now.

Kind regards, Jean-Paul.
Discovering LiveCode Community 6.5.2.

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Problem with searching an array

Post by Thierry » Sun Feb 22, 2015 6:26 pm

atout66 wrote: I've got it to work fine now.
Tu veux dire que ta recherche avec voyelle accentuée fonctionne ?

Si non, j'ai une solution qui semble ok.

Bon dimanche,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: Problem with searching an array

Post by atout66 » Mon Feb 23, 2015 6:25 pm

Tu veux dire que ta recherche avec voyelle accentuée fonctionne ?
Oui :wink:
Yes it works but I changed my mine about the way to get it.
From the Bernd's advice, I first split all the array in a list, do the research, and rebuild the array, it's a global one.

May be it's not the fastest way but it's OK for me.

Kind regards, Jean-Paul.
Discovering LiveCode Community 6.5.2.

Post Reply