Page 1 of 1

Problem with searching an array[Solved]

Posted: Fri Feb 20, 2015 9:01 pm
by atout66
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.

Re: Problem with searching an array

Posted: Sat Feb 21, 2015 6:25 pm
by bn
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

Re: Problem with searching an array

Posted: Sat Feb 21, 2015 8:00 pm
by atout66
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.

Re: Problem with searching an array

Posted: Sun Feb 22, 2015 6:26 pm
by Thierry
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

Re: Problem with searching an array

Posted: Mon Feb 23, 2015 6:25 pm
by atout66
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.