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 229595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:46:45+00:00 2026-05-11T19:46:45+00:00

What is a fast and efficient way to implement the server-side component for an

  • 0

What is a fast and efficient way to implement the server-side component for an autocomplete feature in an html input box?

I am writing a service to autocomplete user queries in our web interface’s main search box, and the completions are displayed in an ajax-powered dropdown. The data we are running queries against is simply a large table of concepts our system knows about, which matches roughly with the set of wikipedia page titles. For this service obviously speed is of utmost importance, as responsiveness of the web page is important to the user experience.

The current implementation simply loads all concepts into memory in a sorted set, and performs a simple log(n) lookup on a user keystroke. The tailset is then used to provide additional matches beyond the closest match. The problem with this solution is that it does not scale. It currently is running up against the VM heap space limit (I’ve set -Xmx2g, which is about the most we can push on our 32 bit machines), and this prevents us from expanding our concept table or adding more functionality. Switching to 64-bit VMs on machines with more memory isn’t an immediate option.

I’ve been hesitant to start working on a disk-based solution as I am concerned that disk seek time will kill performance. Are there possible solutions that will let me scale better, either entirely in memory or with some fast disk-backed implementations?

Edits:

@Gandalf: For our use case it is important the the autocompletion is comprehensive and isn’t just extra help for the user. As for what we are completing, it is a list of concept-type pairs. For example, possible entries are [(“Microsoft”, “Software Company”), (“Jeff Atwood”, “Programmer”), (“StackOverflow.com”, “Website”)]. We are using Lucene for the full search once a user selects an item from the autocomplete list, but I am not yet sure Lucene would work well for the autocomplete itself.

@Glen: No databases are being used here. When I’m talking about a table I just mean the structured representation of my data.

@Jason Day: My original implementation to this problem was to use a Trie, but the memory bloat with that was actually worse than the sorted set due to needing a large number of object references. I’ll read on the ternary search trees to see if it could be of use.

  • 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-11T19:46:46+00:00Added an answer on May 11, 2026 at 7:46 pm

    With a set that large I would try something like a Lucene index to find the terms you want, and set a timer task that gets reset after every key stroke, with a .5 second delay. This way if a user types multiple characters fast it doesn’t query the index every stroke, only when the user pauses for a second. Useability testing will let you know how long that pause should be.

    Timer findQuery = new Timer();
    ...
    public void keyStrokeDetected(..) {
       findQuery.cancel();
       findQuery = new Timer();
       String text = widget.getEnteredText();
       final TimerTask task = new TimerTask() {
          public void run() {
             ...query Lucene Index for matches
          }
       };
       findQuery.schedule(task, 350); //350 ms delay
    }
    

    Some pseduocode there, but that’s the idea. Also if the query terms are set the Lucene Index can be pre-created and optimized.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 511k
  • Answers 511k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What about: function editButtonCallBack(data) { var link = '<%= Html.ImageActionLink("Movement",… May 16, 2026 at 5:14 pm
  • Editorial Team
    Editorial Team added an answer An mmap object "supports the writable buffer interface", therefore you… May 16, 2026 at 5:14 pm
  • Editorial Team
    Editorial Team added an answer getchar() has the side effect of removing the next character… May 16, 2026 at 5:14 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I am looking for ideas on an efficient way to implement a log window
I'm curious if there is an efficient way to wait for the front page
What is the most efficient way to solve system of equations involving the digamma
Duplicate: How do you recommend implementing tags or tagging What's a efficient, fast and
I was wondering what the best way is to implement a tag system, like
Although I know this isn't very efficient, I need to get this working fast
Can anyone recommend a fast way to sort the contents of a text file,
So I need a 2-dimensional ConcurrentHashMap . It has to be as blazing fast
I have a TextBox which I would like to implement undo/redo functionality for. I
My code processes a huge number of values and I'm looking for an efficient

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.