02 April 2015   8 comments   Go, Javascript

Mind That Age!

This blog post is 4 years old! Most likely, its content is outdated. Especially if it's technical.

About a year ago I found a great article about how to use Redis to index every prefix of every word as an index and thus a super fast way of building an autocomplete service. The idea is that you take all your titles and index them like this; if the title is "My Title" you store a key for m, my, t, ti, tit, titl and title. That means you can do very fast lookups as someone is typing unfinished words.

Anyway. I was running this merrily here on my personal blog but I liked it so much and I wanted to use it on aother site for work that I thought it'd be time to extract it into its own little microservice. All I needed was a name and my friend and colleague jezdez suggested I call it "autocompeter". So that it became.

The original implementation was written in Python and at the time I was learning Go and was eager to have something to build in Go. So I built this microservice in Go using the Negroni web framework.

The idea is that you own and run a website. You have a search feature on your website but you don't have a nifty autocomplete (aka. live search) thing on it. So, you send me all your titles, URLs and optionally their "popularity ranking" (basically a score). I'll index them on under your domain. You have to sign in with GitHub to set up an API Auth Key.

Then, you put this into your HTML:

<script src="//"></script>

Also, you'll need to download the CSS and put into your site. I don't recommend pointing to a CDN for CSS.

And that's all you have to do. The REST API, options for the Javascript integration and CSS integration in the documentation.

The Javascript is framework-free meaning it's just pure DOM manipulation and works in IE and modern browsers. The minified file is only 4.2Kb minified (2Kb gzipped).

All code is Open Source under a BSD license. Everything is free but there's no SLA as of yet.

I'm going to be blogging more and more about feature development, benchmarks and other curious things I learn developing this further.


Ursuline Reine

I get a "No 'Access-Control-Allow-Origin' header is present on the requested resource." error :-(

What am I doing wrong?

Peter Bengtsson

What are you trying to do?

Ursuline Reine

I did the curl part, then I created a page with an input, I added the CDN link to it, and the script block too. But as soon as the input field gets focus the ping returns that error.

Seems is not granting access to the request.


Peter Bengtsson

Strange. I'll take a look as soon as I get back to the office.

Ursuline Reine

Hi Peter,
So no news about this?
Thank you.

Ursuline Reine

Cool, thanks!

Andrea Greco

Hi, thanks for the amazing script and all. In your documents API page the example for curl is missing a \ on the first line; -curl -X POST -H "Auth-Key: yoursecurekey"

I could not work out the upload because did not noticed at first, but luckily I did give another try using the same snippet from the Usage section in, now all is fine.


Your email will never ever be published

Related posts

Bye bye httpretty. Welcome back good old mock! 19 March 2015
Autocompeter 1.1.8 and smooth typing 06 April 2015
Related by Keyword:
SongSearch autocomplete rate now 2+ per second 11 July 2019
A darn good search filter function in JavaScript 12 September 2018
How to throttle AND debounce an autocomplete input in React 01 March 2018
Fastest *local* cache backend possible for Django 04 August 2017
Fastest Redis configuration for Django 11 May 2017