Forums/Community/Community tips & tricks

Introducing a script for a quicker ticket search (Zendesk Classic)

Lyman Benton
posted this on April 04, 2012 15:32


When I learned to use search engines, I was always told that including more words will narrow my search.

ZenDesk, however, seems to think the opposite: the more words you include, the more tickets it finds!

It turns out ZenDesk uses more of an "OR" search, while most search engines use "AND" searches. This means Google ensures nearly all searched words are present in results, while ZenDesk piles on as many results as it can find with at least 2/3 of your words included.

The Problem

While ZenDesk provides several useful search tips, I had a problem: even after training my support team on advanced search operators for half a year, they avoided searching in ZenDesk unless absolutely necessary.

ZenDesk search tips:

The Solution

Here are two scripts which narrow search results to require all searched words, and automatically sort by the most recent ticket update. They're not perfect, but our team is finally using the search tool again and quickly finding what they need.

2 words (fixed), 662 results:

To use, copy the following code(s) into a Global JavaScript widget in your (non-Lotus) ZenDesk. This can be found under Settings » Extensions » add widget » Global JavaScript

HOW IT WORKS: The code trims any surrounding whitespace, then if there are multiple words, it prepends + signs in front of each word (unless it is inside quotation marks).

CAUTION: This code uses jQuery and has not been tested for every helpdesk. We have not experienced bugs on our ZenDesk however.

The Code

// SEARCH MOD: require all searched words
jQuery("#topquery").submit(function() {
    if (jQuery("#searchinput").val().indexOf(" ") > 0) jQuery("#searchinput").val((jQuery("#searchinput").val().indexOf("+") == 0 ? "" : "+") + jQuery("#searchinput").val().replace(/\s+(?!\+)(?=([^"]*"[^"]*")*[^"]*$)/g, ' +'));

// SEARCH MOD: default sort by most recent
jQuery(function() {
    jQuery("#topquery").each(function() {
        jQuery(this).append("<input type='hidden' name='by_updated' value='1' \/>");

Questions? Improvements? Comments are welcome!



User photo

Helped me, I was experiencing similar problem, thanks! 

June 01, 2012 13:11
User photo
Jack Bremer
3B Digital

BRILLIANT!!! Thank you :)

August 30, 2012 02:39
User photo
Justin Graves

We are using the new Zendesk interface.  Any chance this would work there?

March 12, 2013 08:17
User photo
Lyman Benton

Hi Justin,

I checked out the new Agent interface and the search is a bit harder to inject scripts into. (Particularly so because you can no longer sort by "Latest Activity" for some reason! What were they thinking?)

I'll have to go back to the drawing board for now -- right now my team has just gone back to using the old ZenDesk.

I'll edit and post here if and when the new search can be enhanced.


March 12, 2013 12:40
User photo
Jennifer Rowe

Hi Lyman, thanks for answering. And thanks for updating the post when/if you create a new solution. Would love to see that. Thanks again!

March 12, 2013 13:40
User photo
Justin Graves

Lyman-  There is a way to sort the search results in the new Zendesk but it's not very elegant (and not in the quick drop-down where it should really be highlighted).  Anyway- thanks for the reply and I would also be interested if you come up with a solution.




March 12, 2013 15:07