Search a multidimensional array

andrew at andrew at
Fri Apr 20 14:32:42 EDT 2018

Is there a quick way to search a large multidimensional array that I  
am missing? I'm working on an inventory system and trying to figure  
out some more efficient methods.

Currently I'm taking a tab-delimited spreadsheet provided by the  
client and converting it to an array, but there are currently > 48000  
keys in the array so my repeat loop for searching is taking several  
minutes. I quickly figured out by making the barcode (unique value)  
the primary key of the array cut down on a simple SKU search, but I'm  
trying to also search based on other values (like the item description).

A line of sample data looks like this:
66290	PHOTO, Early to Mid 1960's, Womens Hair Style, 27x21"	Blue  
Background w/ White Vine Edging, Gold Frame	1	$200.00

An item in the array looks like this:

My slow, albeit working, search code looks like this:
repeat for each element tThisItem in tInventoryArray
       if tThisItem["description"] contains tSearchQuery then
          put tThisItem into tSortedInventoryArray[(the number of  
elements of tSortedInventoryArray) + 1]
       end if
end repeat

This does work, but is taking almost 2 minutes to search through the  
48000+ item database. Can someone point out a flaw in my process? My  
next experiment is converting this array to a SQLlite database and  
just throwing SELECT * WHERE commands at it.

--Andrew Bell

More information about the Use-livecode mailing list