Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added live-search on new-ticket page, to reduce duplication.

git-svn-id: http://store.sabretechllc.com/public/jonmagic/optik/trunk@294 331dd862-6008-0410-a02f-b57fe9264243
  • Loading branch information...
commit 3efd00d24580a7398a4d1d6c7e575cb826495cc8 1 parent 05ca83d
dcparker authored
View
5 app/controllers/tickets_controller.rb
@@ -50,6 +50,11 @@ def search
end
@page_title = 'Search Results'
end
+
+ def similar_search
+ @query = params[:query] || request.raw_post || request.query_string
+ @tickets = Ticket.similar_search(@query, :limit => 8)
+ end
def goto
@ticket = params[:number]
View
18 app/models/ticket.rb
@@ -32,6 +32,24 @@ def self.fullsearch(query, options = {})
end
end
+ def self.similar_search(query, options = {})
+ if !query.to_s.strip.empty?
+ tokens = query.split
+ resultshash = {}
+ Ticket.find_tagged_with(options.merge(:any => tokens)).each do |result|
+ resultshash[result.id] ||= [0, nil]
+ resultshash[result.id][0] += 1
+ resultshash[result.id][1] = result
+ end
+ results = resultshash.keys.collect {|k| resultshash[k][1]}.sort {|b,a| a.updated_at <=> b.updated_at}
+ offset = options.delete(:offset) || 0
+ limit = options.delete(:limit) || 100000
+ return results[offset..(offset+limit)]
+ else
+ []
+ end
+ end
+
# def self.search(query)
# if !query.to_s.strip.empty?
# tokens = query.split.collect {|c| "%#{c.downcase}%"}
View
9 app/views/tickets/new.rhtml
@@ -8,4 +8,11 @@
<%= submit_tag "Create" %>
<%= end_form_tag %>
-</div>
+ <div id="live_similar_search">
+ <!-- search concatenate of fields 'ticket[description]' and 'tags' -->
+ </div>
+</div>
+<%= observe_field 'tags',
+ :update => 'live_similar_search',
+ :url => { :controller => 'tickets', :action=> 'similar_search' },
+ :with => "'query=' + escape(value)" %>
View
7 app/views/tickets/similar_search.rhtml
@@ -0,0 +1,7 @@
+<h4>Is your ticket a duplicate of any of the following?</h4>
+<table id="table-search" class="table">
+ <%= render :partial => "tableheader" %>
+ <% for @ticket in @tickets %>
+ <%= render :partial => "list" %>
+ <% end %>
+</table>
Please sign in to comment.
Something went wrong with that request. Please try again.