---
title: "Improving the search"
slug: improving-the-search
section: tech
date: 2015-07-22T21:33:00.000Z
canonical: https://roland.leth.ro/blog/tech/improving-the-search
---

I wanted a visual representation and helper for the user when a search is performed on the site. So I thought about autocompleting the searched term in the search field. At first I tried with `jQuery`:

```js
var query = decodeURIComponent(location.search)
  .split("=")[1]
  .replace(/[\+]/g, " ");
$('input.search').val(query);
$('input.banner-search').val(query);
```

But this had a small delay and the slight inconvenience of having to replace `+` with a space, and to decode the `URL`. So I ended up with some really simple `ruby`, inside `layout.erb`:

```ruby
<% query_params = request.params['query'] %>
<input type="text" [...] value='<%= query_params %>'/>
```