Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7582971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:34:05+00:00 2026-05-30T18:34:05+00:00

In my web app , i am using jquery ui autocomplete which data are

  • 0

In my web app , i am using jquery ui autocomplete which data are stored in the database (Mysql).

In this application, i have the administration official data And i enable the users to enter their own data. Data will be displayed in the autocomplete drop down list .
The administration data are limited and never change thus are preloaded and cached in memory, however the user data aren’t (since user data grows exponentially and there is no point of using a database if all is to be cached in memory).

So i am doing multi levels caching in my web app, of which, i am caching autocomplete’s user data on the client side (instead of getting them from db on each search).

The scenario is as follow:
When the app loads, the admin data (that are preloaded in memory) are loaded and cached in a JS object to be used in the autocomplete mechanism.

Thus when a user searches for a word, it will check the admin data JS object and if it can’t find it, it will go to db and find it in user data.

So for the case of searching user’s data in db, What i am doing right now is the following:

$( "#search" ).autocomplete({
source:function(request, response) {
var results = $.ui.autocomplete.filter(data, request.term);
if (request.term.toUpperCase() in autocomplete_cache) {
    response($.map(autocomplete_cache[request.term.toUpperCase()], function(item) {
     return {value: item.members.name, md5: item.members.ID}
    }))
   
    return;
   }

where autocomplete_cache is a javascript object:

var autocomplete_cache = {};
// ...it gets filled everytime a new $.post gets new data
...autocomplete_cache[request.term.toUpperCase()] = data;

For the moment, it is caching the exact term searched by a user.

For example, if a user writes "ABCD" and which is not already cached :

–> go to the database (MySQL) do :"WHERE term Like %ABCD%"
–> autocomplete_cache["ABCD"] = "data parsed from mysql"

So if the same USER now retypes "ABCD" it will get it from the autocomplete_cache Object.
However if the USER type "ABC" it won’t get it from the cache object because of the line:

if (request.term.toUpperCase() in autocomplete_cache)

So what i would like to do is to match what the User types in the cache, so in this scenario if the User types "ABC" (which is contained in cache’s "ABCD" String) , the autocomplete will build a drop down list containing "ABCD".

Is there a way of doing that? the reason for this requirement instead of finding the exact String index in the cache object , it will find a wider range and thus limit probabilities of needing to go to db to find the new matches.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:34:06+00:00Added an answer on May 30, 2026 at 6:34 pm

    Instead of looking for a specific key, test each key whether the term is a substring:

    var term = request.term.toUpperCase();
    for (var key in autocomplete_cache) {
        if (key.indexOf(term) > -1) {
            // term is contained in key
        }
    }
    

    And instead of calling response on the first match, collect all matches’ items in an additional array and call response at the end:

    var term = request.term.toUpperCase(),
        items = [];
    for (var key in autocomplete_cache) {
        if (key.indexOf(term) > -1) {
            items.merge($.map(autocomplete_cache[key], function(item) {
                return {value: item.members.name, md5: item.members.ID}
            });
        }
    }
    if (items.length > 0) response(items);
    

    You might also want to remove any duplicates in items and sort the resulting items before calling response:

    var term = request.term.toUpperCase(),
        items = [],
        index = {};
    for (var key in autocomplete_cache) {
        if (key.indexOf(term) > -1) {
            $.each(autocomplete_cache[key], function(item) {
                var id = item.members.ID;
                if (!index[id]) {
                    items.push({value: item.members.name, md5: item.members.ID});
                    index[id] = true;
                }
            });
        }
    }
    items.sort(function(a, b) { return a.name.localeCompare(b.name); });
    if (items.length > 0) response(items);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this strange issue with my web app. You see, I'm using jQuery
Say I have a mobile web app written using JQuery Mobile, this app retrieves
I'm developing a web app in asp.net mvc using jquery, the language of application
I've been toying with writing a web app using jquery mobile which makes use
I'm using jquery.history plugin in my web-app and have a problem with '/' being
I have a web app done for mobile platform using jquery-mobile. It works fine
I am currently working on a web app using Wicket and started using jQuery
I am developing a web app using servlets and jsps. I have a question
I have a web app using forms authentication and I have restricted a folder
I have developed a web app using a webservice. Everything works fine in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.