Skip to content

The value auto-completer

July 11, 2011

In  a previous post I discussed the search declaration line and the way a developer can define the search syntax and it’s auto-completer. In this post I will elaborate on the value completion feature of the scoped_search.

Adding a value auto-completer is done by simply adding “:complete_value => true” to the declaration line.  For example:

scoped_search :on => :title, :complete_value => true

This short declaration is all  that is needed to create a value completion list, drawn from the database. The user will be able  to select from the list, or start typing to make the list shorter.

This solution fits many cases, but sometimes the possible values are a known set of values, that is not necessarily in the database.

In a chat application for example, a user can be “online”, “offline” or “away from keyboard”, in this case we will want the auto-completer to suggest all possible values even if, at the time the query is written, one of the values doesn’t exist in the database. Actually it would be better if the auto-completer will not access the database at all for that purpose. It’s even better if we could translate the search term in a way that the terms will be readable in the search but represented efficiently  in the database, integer could be good candidate for the status column in the example.

To do just that we can write the scoped_search declaration as follow:

scoped_search :on => status, :complete_value => {:offline => 0, :online => 1, :away => 2}

The auto completer will suggest all possible values in a human readable way and the query will use the the matching integer for the search execution.

Advertisements

From → Developers

One Comment
  1. Uri Keidar permalink

    Thanks, it is very simple as I can testify myself.
    Just adding the complete_value=true did the trick

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: