PDA

View Full Version : speeding up XML string searches



killjoyboy
April 11th, 2007, 12:31 AM
Hi everyone, this is my first time posting here so bear with me if this post is a little long winded, i just want to clearly get across my question. also, props are due to kirupa.com cause this site is indispensable - i've definitely used this site for reference many many times before!

anyway getting to the point...

so i'm trying to implement a string search of an XML document that is pretty huge (a directory with ~15,000 entries), and i want to implement search functionality similar to iTunes. This means that when the user begins typing into the search field it automatically updates the results as he/she is typing. The problem arises with the amount of time it takes to return results for single letter searches and other such general searches - for example when i search for "z" it takes a prohibitively long time to execute and i get a dialog box asking me if i want to stop the script. This is a basic rundown of how i'm running the search (its pretty primitive, i've basically created this as a test to see how fast flash can search large XML documents):

- i have load an external XML document into an XML object in flash

- the XML data is set up so that each entry is a node, and all information for each entry is stored in attributes (i.e. <root><entry name="villa, bob" phone="8005552222"></entry><entry name="antoinette, mary"... etc.)

- i use a for loop to go through each node and use the String.indexOf() method to find out if there is a search criteria match in each XML attribute, and if there is a list them in a text field


Does anyone have any tips on how to speed up my search? Is it an XML issue or is it a String search using indexOf() issue? I've read about using XPathAPI but haven't tried it yet, but i suspect that my problem is more to do with the String searching. Are there more efficient ways to search strings? And what are some ways to speed up XML interaction in flash, in respect to searching?

Thanks so much in advance, I have a big project coming up depending on this and I'm struggling to find any kind of documentation on this.

killjoyboy

bwh2
April 11th, 2007, 08:39 AM
in my opinion, 15,000 entries means this should be in SQL. that would allow for much more powerful searching.

foodpk
April 11th, 2007, 09:17 AM
Yeah, like bwh2 said.
What you should do is put all that data in an SQL database. For example, MySQL. Then, instead of loading up the full hojillion entries into flash into the XML object, you would actually call a php file which would in turn output data in the form of XML to flash.
Instead of doing
XML.load("yourfile.xml") you'd be doing
XML.load("something.php?search=" + yourSearchVariable);
Of course you can give it as many parameters as you want. The php file would basically contain a connection to the database, it would search it according to the GET contents (in this case, yourSearchVariable) and would return, say, the 15 most relevant results.

killjoyboy
April 25th, 2007, 04:06 PM
i appreciate the help but the directory i'm implementing is for use on a local machine, we're just using flash and xml to deploy it on cd to users. so basically using a database like MySQL is not an option.

i have, however found some really useful information in the following link:

http://www.craftymind.com/category/flash

basically its a solution to exactly what i need to do, using flex and actionscript 3. thanks for the suggestions anyway!