Browse Source

Added init version of ES search.

Martin Edenhofer 11 years ago
parent
commit
b163b2eb0f
3 changed files with 33 additions and 0 deletions
  1. 11 0
      app/models/organization/search.rb
  2. 11 0
      app/models/ticket/search.rb
  3. 11 0
      app/models/user/search.rb

+ 11 - 0
app/models/organization/search.rb

@@ -28,6 +28,17 @@ returns
     # enable search only for agents and admins
     return [] if !current_user.is_role('Agent') && !current_user.is_role('Admin')
 
+    # try search index backend
+    if Setting.get('es_url')
+      ids = SearchIndexBackend.search( query, limit, 'Organization' )
+      organizations = []
+      ids.each { |id|
+        organizations.push Organization.lookup( :id => id )
+      }
+      return organizations
+    end
+
+    # fallback do sql query
     # do query
     organizations = Organization.find(
       :all,

+ 11 - 0
app/models/ticket/search.rb

@@ -40,6 +40,17 @@ returns
       end
     end
 
+    # try search index backend
+    if Setting.get('es_url')
+      ids = SearchIndexBackend.search( query, limit, 'Ticket' )
+      tickets = []
+      ids.each { |id|
+        tickets.push Ticket.lookup( :id => id )
+      }
+      return tickets
+    end
+
+    # fallback do sql query
     # do query
     tickets_all = Ticket.select('DISTINCT(tickets.id)').
     where(conditions).

+ 11 - 0
app/models/user/search.rb

@@ -44,6 +44,17 @@ returns
     # enable search only for agents and admins
     return [] if !current_user.is_role('Agent') && !current_user.is_role('Admin')
 
+    # try search index backend
+    if Setting.get('es_url')
+      ids = SearchIndexBackend.search( query, limit, 'User' )
+      users = []
+      ids.each { |id|
+        users.push User.lookup( :id => id )
+      }
+      return users
+    end
+
+    # fallback do sql query
     # do query
     users = User.find(
       :all,