Making advanced search forms for your backend kinda sucks, right? I ran into this problem with a project and decided to come up with something similar to how Google handles search queries. No dropdowns, no checkboxes, no radios, none of that stuff. I just wanted to be able to type status:active user:rob [term] and get what I asked for. I came up with a pretty nice utility class that can handle some basic query syntaxes and give you back hashes or arrays and the left over query.
With this class I can make links that perform my basic “advanced” queries, without littering the query string. For example, if I wanted to ‘get a list of all guest users with the name “jake” in NJ, NY, or FL’ I could search for the following: guest:true state:nj,ny,fl jake. I would then take that in the controller’s params and parse it out using terms = SearchTerms.new(params[:q]) which would give me the elements broken down:
Rob Hurring is a software engineer residing in the NJ tri-state area. He spends most of his time writing Ruby code or hacking on whatever he finds neat.