Log Live Search Keywords

Hi,

I’ve got a live search tool in my app. Works like a charm, with some jquery, ajax and a search action in my controller.

Now I want to log the search terms. But every key is send to the search action, and while this is OK for my search, it’s not what I want to log.

When you search:

"I like yii"

10 records are saved:

I

I

I l

I li

I lik

I like

I like

I like y

I like yi

I like yii

How can I prevent this, without too much performance lost?

I suppose you’ll only know that the user has finished searching when they choose one of the results, so the logical solution is to send an ajax request to a search logging action when the user picks a result and before they’re redirected to the relevant page. You could capture the search term and the result that the user chose, which might be useful in the future for prioritising search results.

Thanks Keith.

True, but when they don’t click or any results are found, I can’t log is. What I want to do, is make it more sophisticated later and use this data for suggesting search terms when the user is making a typo etc.

I’ve been thinking to delete a previous log record of a user when within 0.5 seconds or so.

But I think the best solution is to make a timeout on the jquery side.

I was just curious if anyone have dealt with this before and maybe got a good tip for me. If so, please let me know.

Maybe remove recent results that match the beginning of the latest search string?

Hm, good thinking. Gonne test that, will come back later on this topic.