Tuesday, 15 April 2014

javascript - How to search effectively and fastly when we have 50,000 of JSON Data? -



javascript - How to search effectively and fastly when we have 50,000 of JSON Data? -

i have json info follows

var data=[ { name: "aaa", phone : "1" }, { name: "bbb", phone : "2" }, | | | | |, { name: "z50000", phone : "50000" } ]

i searching records contains specific keyword (either name / phone). using javascript that. tried next way

var searchkeyword=document.getelementbyid("txtsearchkeyword").value; var searchdata=new array(); for(var i=0;i<data.length;i++){ if(data.name.index(searchkeyword) !=-1 || data.phone.index(searchkeyword) !=-1){ searchdata.push(data[i]); } }

everything working fine, taking noticeable amount of time. how can search efficiently , fastly when have big amound of info ?

aside hayes mentioned utilizing regex, if info sorted (as seems) utilize binary search. should run in o(log n) time right me if i'm wrong.

for example:

while not found compare middle of info array searching if match, homecoming if searching > midpoint, phone call recursively on middle of lastly half else recursively phone call on middle of first half of array

edit: turns out misread question. i'm leaving code sample in case find in google search , wants search array of jsons

javascript jquery json search

No comments:

Post a Comment