Re: Sorting search results - solution needed
Hey guys, thanks for all the possible solutions. I'm sure somewhere in here I'll get it to do what I need. Special thanks to those that wrote code. Much appreciate it! Scott On 10/24/18, 1:28 PM, "use-livecode on behalf of Niggemann, Bernd via use-livecode" wrote: here is my take, clumsy and not respecting all formatting requirements Instead of 187.1 187.1.1 187.1.2 187.3 187.22 187.33 187.234 it sorts 187.1 187.1.1 187.1.2 187.22 187.234 187.3 187.33 Kind regards Bernd --- on mouseUp put field "fAlpha" into tData put "" into msg sort tData numeric by specialSort(each) put tData into field "fSort" end mouseUp function specialSort pEach put pEach into tData --put word 1 to -1 of tData into tData put "0,1,2,3,4,5,6,7,8,9,." into tNumbers -- check for double colon like in 187.1.2 put 0 into tSkip put 0 into tCounter repeat put offset(".", tData, tSkip) into tOffset if tOffset > 0 then add tOffset to tSkip add 1 to tCounter else exit repeat end if end repeat if tCounter > 1 then --put tData && tCounter & cr after msg put empty into char tSkip of tData return tData end if repeat with i = 1 to the number of chars of tData if char i of tData is among the items of tNumbers then put char i of tData after tNumberPart else exit repeat end if end repeat if tData = tNumberPart then return tNumberPart end if put length(tNumberPart) into tLength put char tLength + 1 to - 1 of tData into tRest if char tLength of tNumberPart = "." then put "." before tRest replace ")" with empty in tRest replace space with empty in tRest put toUpper(tRest) into tRest put true into tLeftBracket put 0 into tDecimal repeat with i = 1 to the number of chars of tRest put char i of tRest into tChar if tChar is a Number then add tChar * .1 to tDecimal else if tChar is "(" then if tLeftBracket then add .001 to tDecimal put false into tLeftBracket end if else if tChar is "." then -- ASCII "." = 46 add .1 to tDecimal else if charToNum(tChar) >= 65 then -- ASCII "A" = 65 add (charToNum(tChar)-64) * .9 to tDecimal end if end repeat return tNumberPart + tDecimal end specialSort - ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Sorting search results - solution needed
here is my take, clumsy and not respecting all formatting requirements Instead of 187.1 187.1.1 187.1.2 187.3 187.22 187.33 187.234 it sorts 187.1 187.1.1 187.1.2 187.22 187.234 187.3 187.33 Kind regards Bernd --- on mouseUp put field "fAlpha" into tData put "" into msg sort tData numeric by specialSort(each) put tData into field "fSort" end mouseUp function specialSort pEach put pEach into tData --put word 1 to -1 of tData into tData put "0,1,2,3,4,5,6,7,8,9,." into tNumbers -- check for double colon like in 187.1.2 put 0 into tSkip put 0 into tCounter repeat put offset(".", tData, tSkip) into tOffset if tOffset > 0 then add tOffset to tSkip add 1 to tCounter else exit repeat end if end repeat if tCounter > 1 then --put tData && tCounter & cr after msg put empty into char tSkip of tData return tData end if repeat with i = 1 to the number of chars of tData if char i of tData is among the items of tNumbers then put char i of tData after tNumberPart else exit repeat end if end repeat if tData = tNumberPart then return tNumberPart end if put length(tNumberPart) into tLength put char tLength + 1 to - 1 of tData into tRest if char tLength of tNumberPart = "." then put "." before tRest replace ")" with empty in tRest replace space with empty in tRest put toUpper(tRest) into tRest put true into tLeftBracket put 0 into tDecimal repeat with i = 1 to the number of chars of tRest put char i of tRest into tChar if tChar is a Number then add tChar * .1 to tDecimal else if tChar is "(" then if tLeftBracket then add .001 to tDecimal put false into tLeftBracket end if else if tChar is "." then -- ASCII "." = 46 add .1 to tDecimal else if charToNum(tChar) >= 65 then -- ASCII "A" = 65 add (charToNum(tChar)-64) * .9 to tDecimal end if end repeat return tNumberPart + tDecimal end specialSort - ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Sorting search results - solution needed
I think this comes pretty close to the requirement. It breaks the lines down into numeric/not numeric items, and then sorts from the least significant (rightmost) to most significant items. For each sort, sorts first by alpha, then numeric. That results in letters being sorted before numbers, which seemed wrong for this application, so I added the returnOnlyNumbers function that (nearly) guarantees letters sorting after numbers. If the parenthesis etc. gets in the way, then removing them from the sort could be done by building an array mapping the original list to the sort keys, and then sorting on a function that returns the appropriate sort key. But for now this seems pretty close. function sortByAlternateNumericItems lineList,D -- takes a line list and a delimiter D that must not be in the lineList -- breaks each line down into numeric/non-numeric items -- then sorts by the items, from least significant (rightmost) to most significant. -- for each sort, sorts first by alpha, then numeric, so numbers sort before letters if D is in lineList then answer warning D && "is in the list" with cancel exit to top end if put 0 into maxItems repeat for each line L in lineList put numericItems(L,D) into newL get the number of items of newL if it > maxItems then put it into maxItems put newL & cr after R end repeat delete char -1 of R set the itemDel to D repeat with i = maxItems down to 1 sort lines of R by item i of each sort lines of R numeric by returnOnlyNumbers(item i of each) end repeat replace D with empty in R return R end sortByAlternateNumericItems function returnOnlyNumbers N if N is a number then return N else return 999 end returnOnlyNumbers function numericItems S,D -- returns the string S broken into number/not-number items, delimited by D -- D must be chosen so that it does not occur in S if D is in S then answer warning D && "is in" && S with cancel exit to top end if put char 1 of S is a number into isNum put 1 into B repeat with E = 2 to length(S) if isNum then if (char B to E of S is a number) then next repeat put (char B to E - 1 of S) & D after R put E into B put false into isNum else if char B to E of S is a number then put true into isNum else repeat with NB = B + 1 to E if char NB to E of S is not a number then next repeat put (char B to NB - 1 of S) & D after R put NB into B put true into isNum exit repeat end repeat end if end repeat return R & char B to E of S end numericItems This sorts this list: 187 187.01 187.02 187.1 187.22 187.234 187.3 187.33 187.456 10187 18700 187 (a) 187 (b) 187 (b)(1) 187 (a)(1) 187.1.1 187.1.2 187.c 187a 187c 187 a 187 1 1 a c b to this: 1 187 187a 187c 187 1 187 (a) 187 (a)(1) 187 (b) 187 (b)(1) 187 a 187.c 187.01 187.02 187.1.1 187.1.2 187.1 187.22 187.234 187.3 187.33 187.456 10187 18700 a b c On Wed, Oct 24, 2018 at 9:08 AM Bob Sneidar via use-livecode < use-livecode@lists.runrev.com> wrote: > I should have said, in the loop keep adding a character until the value is > no longer a number, then sort numeric by the last value. > > Bob S > > > > On Oct 23, 2018, at 14:14 , Bob Sneidar via use-livecode < > use-livecode@lists.runrev.com> wrote: > > > > This of course cannot be a numeric sort. I would create a loop and start > with 1 digit, then see if the value div the value = the value (in a try > catch loop). Once you get an error or false, break out the integer portion, > pad it with the appropriate number of trailing zeros, then append the rest. > > > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your > subscription preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode > ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Sorting search results - solution needed
I should have said, in the loop keep adding a character until the value is no longer a number, then sort numeric by the last value. Bob S > On Oct 23, 2018, at 14:14 , Bob Sneidar via use-livecode > wrote: > > This of course cannot be a numeric sort. I would create a loop and start with > 1 digit, then see if the value div the value = the value (in a try catch > loop). Once you get an error or false, break out the integer portion, pad it > with the appropriate number of trailing zeros, then append the rest. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Sorting search results - solution needed
As Craig said, your rules are not consistent to standards: You sort *after* the first period numeric with the exception that leading zeros are "valid". That's why the replace in the following function is needed. This now yields exactly your custom sort order: function gregSort s set itemdel to "." sort s numeric by offset("a",each) sort s numeric by offset("b",each) sort s numeric by offset("c",each) replace ".0" with ".0." in s --> begin make leading zeros valid sort s numeric by item 2 to 3 of each replace ".0." with ".0" in s --> end make leading zeros valid sort s numeric by item 1 of each return s end gregSort ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Sorting search results - solution needed
I am missing the rules of the game. But in any event I agree that the only way to sort a mixed bag of numbers, punctuation and alpha chars is to pre-parse and sort repeatedly by items, or some other, er, sort of chunk. But I do not see the "hierarchy" among spaces, periods, decimal numbers, etc. Are there such rules? Craig Newman -- Sent from: http://runtime-revolution.278305.n4.nabble.com/Revolution-User-f278306.html ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Sorting search results - solution needed
Okay I misunderstood. So were it not for the multiple periods in a single value, you could have sorted numeric by word 1 of each, then resorted alphabetically by word 2 of each. The wrench in the works is the double periods. For this you can write a function that builds a string for a value passed and use that in your by each clause. I would extract the integer portion of the value, pad it with a maximum number of trailing zeros, say 10, then append the rest. So for example 187 becomes 187000. 187a becomes 187000a. 187.01 mecomes 187000.01. 187 (a) becomes 187000 (a). And finally, 10187 becomes 101870. This of course cannot be a numeric sort. I would create a loop and start with 1 digit, then see if the value div the value = the value (in a try catch loop). Once you get an error or false, break out the integer portion, pad it with the appropriate number of trailing zeros, then append the rest. Bob S > 187 > 187a > 187 (a) > 187 (a)(1) > 187 (b) > 187 (b)(1) > 187c > 187.c > 187.01 > 187.02 > 187.1 > 187.1.1 > 187.1.2 > 187.3 > 187.22 > 187.33 > 187.234 > 187.456 > 10187 > 18700 Bob S ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Sorting search results - solution needed
Come to think of it no. I didn't notice the items further down in the list with multiple periods. Your problems is very basic: You really have alpha-numeric data, which you are trying to sort numerically. It's a contradiction in terms. Looking at the nature of your data, and assuming your data is not going to deviate from what you have provided, you have to break out the components of your values into three separate values, the integer portion (if any otherwise 0), the decimal portion (if any otherwise 0) and the alphanumeric portion (assuming that *ALWAYS* comes last). But evn then, I see: >> 10187 >> >> 187c >> >> 18700 That's not alphanumerically sorted, nor is it numerically sorted! It's a non-sort! Bob S > On Oct 23, 2018, at 13:45 , Bob Sneidar via use-livecode > wrote: > > sort lines numeric by word 1 of each > >> On Oct 23, 2018, at 12:22 , Scott Seward via use-livecode >> wrote: >> >> Hi, >> >> I need to sort the result set of a search. But the common sort mechanisms >> I’m familiar with won’t get me where I need. I’m sure this is a common >> problem and much better developers then I know the name of it and how to >> execute it in Livecode. Any help would be appreciated. Here is the problem: >> >> I execute a search for “187” and get the following results: >> >> NOTE: The search term will always start with one or more numeric characters >> and possibly be appended by punctuation or other alpha characters. >> >> Alpha sort >> >> Desired Sort >> >> 187 >> >> 187 >> >> 187.01 >> >> 187a >> >> 187.02 >> >> 187 (a) >> >> 187.1 >> >> 187 (a)(1) >> >> 187.22 >> >> 187 (b) >> >> 187.234 >> >> 187 (b)(1) >> >> 187.3 >> >> 187c >> >> 187.33 >> >> 187.c >> >> 187.456 >> >> 187.01 >> >> 10187 >> >> 187.02 >> >> 18700 >> >> 187.1 >> >> 187 (a) >> >> 187.1.1 >> >> 187 (a)(1) >> >> 187.1.2 >> >> 187 (b) >> >> 187.3 >> >> 187 (b)(1) >> >> 187.22 >> >> 187.1.1 >> >> 187.33 >> >> 187.1.2 >> >> 187.234 >> >> 187.c >> >> 187.456 >> >> 187a >> >> 10187 >> >> 187c >> >> 18700 >> >> >> >> Kindest regards, >> >> Scott >> >> >> ___ >> use-livecode mailing list >> use-livecode@lists.runrev.com >> Please visit this url to subscribe, unsubscribe and manage your subscription >> preferences: >> http://lists.runrev.com/mailman/listinfo/use-livecode > > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your subscription > preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Sorting search results - solution needed
Hmm, interesting. I'll noodle on that. I also see my email is pretty unreadable without any formatting. Here is a slightly better data example. Alpha sort 187 187.01 187.02 187.1 187.22 187.234 187.3 187.33 187.456 10187 18700 187 (a) 187 (a)(1) 187 (b) 187 (b)(1) 187.1.1 187.1.2 187.c 187a 187c Desired SORT 187 187a 187 (a) 187 (a)(1) 187 (b) 187 (b)(1) 187c 187.c 187.01 187.02 187.1 187.1.1 187.1.2 187.3 187.22 187.33 187.234 187.456 10187 18700 On 10/23/18, 12:49 PM, "use-livecode on behalf of Kee Nethery via use-livecode" wrote: I’d deconstruct the values into separate items and then sort by the last item, then next to last, eventually getting to the first. Kee Nethery > On Oct 23, 2018, at 12:22 PM, Scott Seward via use-livecode wrote: > > Hi, > > I need to sort the result set of a search. But the common sort mechanisms I’m familiar with won’t get me where I need. I’m sure this is a common problem and much better developers then I know the name of it and how to execute it in Livecode. Any help would be appreciated. Here is the problem: > > I execute a search for “187” and get the following results: > > NOTE: The search term will always start with one or more numeric characters and possibly be appended by punctuation or other alpha characters. > > Alpha sort > > Desired Sort > > 187 > > 187 > > 187.01 > > 187a > > 187.02 > > 187 (a) > > 187.1 > > 187 (a)(1) > > 187.22 > > 187 (b) > > 187.234 > > 187 (b)(1) > > 187.3 > > 187c > > 187.33 > > 187.c > > 187.456 > > 187.01 > > 10187 > > 187.02 > > 18700 > > 187.1 > > 187 (a) > > 187.1.1 > > 187 (a)(1) > > 187.1.2 > > 187 (b) > > 187.3 > > 187 (b)(1) > > 187.22 > > 187.1.1 > > 187.33 > > 187.1.2 > > 187.234 > > 187.c > > 187.456 > > 187a > > 10187 > > 187c > > 18700 > > > > Kindest regards, > > Scott > > > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your subscription preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Sorting search results - solution needed
sort lines numeric by word 1 of each > On Oct 23, 2018, at 12:22 , Scott Seward via use-livecode > wrote: > > Hi, > > I need to sort the result set of a search. But the common sort mechanisms I’m > familiar with won’t get me where I need. I’m sure this is a common problem > and much better developers then I know the name of it and how to execute it > in Livecode. Any help would be appreciated. Here is the problem: > > I execute a search for “187” and get the following results: > > NOTE: The search term will always start with one or more numeric characters > and possibly be appended by punctuation or other alpha characters. > > Alpha sort > > Desired Sort > > 187 > > 187 > > 187.01 > > 187a > > 187.02 > > 187 (a) > > 187.1 > > 187 (a)(1) > > 187.22 > > 187 (b) > > 187.234 > > 187 (b)(1) > > 187.3 > > 187c > > 187.33 > > 187.c > > 187.456 > > 187.01 > > 10187 > > 187.02 > > 18700 > > 187.1 > > 187 (a) > > 187.1.1 > > 187 (a)(1) > > 187.1.2 > > 187 (b) > > 187.3 > > 187 (b)(1) > > 187.22 > > 187.1.1 > > 187.33 > > 187.1.2 > > 187.234 > > 187.c > > 187.456 > > 187a > > 10187 > > 187c > > 18700 > > > > Kindest regards, > > Scott > > > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your subscription > preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Sorting search results - solution needed
I’d deconstruct the values into separate items and then sort by the last item, then next to last, eventually getting to the first. Kee Nethery > On Oct 23, 2018, at 12:22 PM, Scott Seward via use-livecode > wrote: > > Hi, > > I need to sort the result set of a search. But the common sort mechanisms I’m > familiar with won’t get me where I need. I’m sure this is a common problem > and much better developers then I know the name of it and how to execute it > in Livecode. Any help would be appreciated. Here is the problem: > > I execute a search for “187” and get the following results: > > NOTE: The search term will always start with one or more numeric characters > and possibly be appended by punctuation or other alpha characters. > > Alpha sort > > Desired Sort > > 187 > > 187 > > 187.01 > > 187a > > 187.02 > > 187 (a) > > 187.1 > > 187 (a)(1) > > 187.22 > > 187 (b) > > 187.234 > > 187 (b)(1) > > 187.3 > > 187c > > 187.33 > > 187.c > > 187.456 > > 187.01 > > 10187 > > 187.02 > > 18700 > > 187.1 > > 187 (a) > > 187.1.1 > > 187 (a)(1) > > 187.1.2 > > 187 (b) > > 187.3 > > 187 (b)(1) > > 187.22 > > 187.1.1 > > 187.33 > > 187.1.2 > > 187.234 > > 187.c > > 187.456 > > 187a > > 10187 > > 187c > > 18700 > > > > Kindest regards, > > Scott > > > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your subscription > preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Sorting search results - solution needed
Hi, I need to sort the result set of a search. But the common sort mechanisms I’m familiar with won’t get me where I need. I’m sure this is a common problem and much better developers then I know the name of it and how to execute it in Livecode. Any help would be appreciated. Here is the problem: I execute a search for “187” and get the following results: NOTE: The search term will always start with one or more numeric characters and possibly be appended by punctuation or other alpha characters. Alpha sort Desired Sort 187 187 187.01 187a 187.02 187 (a) 187.1 187 (a)(1) 187.22 187 (b) 187.234 187 (b)(1) 187.3 187c 187.33 187.c 187.456 187.01 10187 187.02 18700 187.1 187 (a) 187.1.1 187 (a)(1) 187.1.2 187 (b) 187.3 187 (b)(1) 187.22 187.1.1 187.33 187.1.2 187.234 187.c 187.456 187a 10187 187c 18700 Kindest regards, Scott ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode