Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of https://github.com/nisargshah100/speakeasy_app

… into modal
  • Loading branch information...
commit 805059bf62e48f0393a92f6e96dfd70d8c25e505 2 parents 9156afc + 6ae3f72
@mikesea mikesea authored
Showing with 127 additions and 29 deletions.
  1. +5 −5 services.god
  2. +1 −0  speakeasy_gumshoe/Gemfile
  3. +7 −0 speakeasy_gumshoe/Gemfile.lock
  4. +5 −2 speakeasy_gumshoe/app/controllers/api/searches_controller.rb
  5. +6 −1 speakeasy_gumshoe/app/models/query_item.rb
  6. +1 −1  speakeasy_gumshoe/config/development.sphinx.conf
  7. +1 −0  speakeasy_gumshoe/db/migrate/20120606231135_create_query_items.rb
  8. +1 −0  speakeasy_gumshoe/db/schema.rb
  9. BIN  speakeasy_gumshoe/db/sphinx/development/query_item_core.spa
  10. BIN  speakeasy_gumshoe/db/sphinx/development/query_item_core.spd
  11. BIN  speakeasy_gumshoe/db/sphinx/development/query_item_core.sph
  12. BIN  speakeasy_gumshoe/db/sphinx/development/query_item_core.spi
  13. 0  speakeasy_gumshoe/db/sphinx/development/query_item_core.spl
  14. BIN  speakeasy_gumshoe/db/sphinx/development/query_item_core.sps
  15. +18 −7 speakeasy_gumshoe/lib/tasks/sub.rake
  16. +1 −0  speakeasy_gumshoe/log/searchd.development.pid
  17. +54 −0 speakeasy_vaudeville/app/assets/javascripts/app/controllers/search.js.coffee
  18. +2 −0  speakeasy_vaudeville/app/assets/javascripts/app/index.js.coffee
  19. +16 −13 speakeasy_vaudeville/app/assets/javascripts/app/models/faye.js.coffee
  20. +4 −0 speakeasy_vaudeville/app/assets/javascripts/app/views/rooms/search.jst.eco
  21. +5 −0 speakeasy_vaudeville/app/views/app/index.html.erb
View
10 services.god
@@ -60,11 +60,11 @@ God.watch do |w|
w.keepalive
end
-God.watch do |w|
- w.name = "search redis server"
- w.start = "cd #{path}/speakeasy_gumshoe/; rake subscribe"
- w.keepalive
-end
+# God.watch do |w|
+# w.name = "search redis server"
+# w.start = "cd #{path}/speakeasy_gumshoe/; rake subscribe"
+# w.keepalive
+# end
God.watch do |w|
w.name = "search indexer"
View
1  speakeasy_gumshoe/Gemfile
@@ -26,6 +26,7 @@ gem 'thinking-sphinx'
gem 'draper'
gem 'redis'
gem 'thin'
+gem 'speakeasy_on_tap', path: '../speakeasy_on_tap'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
View
7 speakeasy_gumshoe/Gemfile.lock
@@ -1,3 +1,9 @@
+PATH
+ remote: ../speakeasy_on_tap
+ specs:
+ speakeasy_on_tap (0.0.1)
+ redis
+
GEM
remote: https://rubygems.org/
specs:
@@ -126,6 +132,7 @@ DEPENDENCIES
rails (= 3.2.3)
redis
sass-rails (~> 3.2.3)
+ speakeasy_on_tap!
sqlite3
thin
thinking-sphinx
View
7 speakeasy_gumshoe/app/controllers/api/searches_controller.rb
@@ -2,9 +2,12 @@ class Api::SearchesController < ApplicationController
def show
query = params[:query]
+ ns = params[:ns]
- if query
- results = QueryItemDecorator.search(query).map { |i| i.decorate() if i }
+ if query and ns
+ results = QueryItemDecorator.by_ns(ns).search(query).map do |i|
+ i.decorate() if i
+ end
else
results = {}
end
View
7 speakeasy_gumshoe/app/models/query_item.rb
@@ -1,7 +1,12 @@
class QueryItem < ActiveRecord::Base
- attr_accessible :content, :query
+ attr_accessible :content, :query, :ns
define_index do
indexes query
+ indexes ns
+ end
+
+ sphinx_scope(:by_ns) do |ns|
+ {:conditions => {:ns => ns }}
end
end
View
2  speakeasy_gumshoe/config/development.sphinx.conf
@@ -19,7 +19,7 @@ source query_item_core_0
sql_db = gumshoe_dev
sql_query_pre = SET NAMES utf8
sql_query_pre = SET TIME_ZONE = '+0:00'
- sql_query = SELECT SQL_NO_CACHE `query_items`.`id` * CAST(1 AS SIGNED) + 0 AS `id` , `query_items`.`query` AS `query`, `query_items`.`id` AS `sphinx_internal_id`, 0 AS `sphinx_deleted`, 2455488101 AS `class_crc`, IFNULL('QueryItem', '') AS `sphinx_internal_class` FROM `query_items` WHERE (`query_items`.`id` >= $start AND `query_items`.`id` <= $end) GROUP BY `query_items`.`id` ORDER BY NULL
+ sql_query = SELECT SQL_NO_CACHE `query_items`.`id` * CAST(1 AS SIGNED) + 0 AS `id` , `query_items`.`query` AS `query`, `query_items`.`ns` AS `ns`, `query_items`.`id` AS `sphinx_internal_id`, 0 AS `sphinx_deleted`, 2455488101 AS `class_crc`, IFNULL('QueryItem', '') AS `sphinx_internal_class` FROM `query_items` WHERE (`query_items`.`id` >= $start AND `query_items`.`id` <= $end) GROUP BY `query_items`.`id` ORDER BY NULL
sql_query_range = SELECT IFNULL(MIN(`id`), 1), IFNULL(MAX(`id`), 1) FROM `query_items`
sql_attr_uint = sphinx_internal_id
sql_attr_uint = sphinx_deleted
View
1  speakeasy_gumshoe/db/migrate/20120606231135_create_query_items.rb
@@ -3,6 +3,7 @@ def change
create_table :query_items do |t|
t.string :query
t.text :content
+ t.string :ns
t.timestamps
end
View
1  speakeasy_gumshoe/db/schema.rb
@@ -16,6 +16,7 @@
create_table "query_items", :force => true do |t|
t.string "query"
t.text "content"
+ t.string "ns"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
View
BIN  speakeasy_gumshoe/db/sphinx/development/query_item_core.spa
Binary file not shown
View
BIN  speakeasy_gumshoe/db/sphinx/development/query_item_core.spd
Binary file not shown
View
BIN  speakeasy_gumshoe/db/sphinx/development/query_item_core.sph
Binary file not shown
View
BIN  speakeasy_gumshoe/db/sphinx/development/query_item_core.spi
Binary file not shown
View
0  speakeasy_gumshoe/db/sphinx/development/query_item_core.spl
No changes.
View
BIN  speakeasy_gumshoe/db/sphinx/development/query_item_core.sps
Binary file not shown
View
25 speakeasy_gumshoe/lib/tasks/sub.rake
@@ -1,12 +1,23 @@
task :subscribe => :environment do
- $redis.subscribe 'new_message' do |on|
- on.message do |channel, json_data|
- data = JSON.parse(json_data) rescue {}
+ # $redis.subscribe 'new_message' do |on|
+ # on.message do |channel, json_data|
+ # data = JSON.parse(json_data) rescue {}
- if data and data != {}
- QueryItem.create(:query => data['message'], :content => json_data)
- puts "Added new message to search! #{json_data}"
- end
+ # if data and data != {}
+ # QueryItem.create(:query => data['message'], :content => json_data)
+ # puts "Added new message to search! #{json_data}"
+ # end
+ # end
+ # end
+
+ SpeakeasyOnTap::subscribe_to_channels(:created_messages) do |channel, data|
+ if data and data != {}
+ QueryItem.create(
+ :query => data['body'],
+ :content => data.to_json,
+ :ns => "[room]#{data['room_id']}")
+
+ puts "Inserted #{data}"
end
end
end
View
1  speakeasy_gumshoe/log/searchd.development.pid
@@ -0,0 +1 @@
+12091
View
54 speakeasy_vaudeville/app/assets/javascripts/app/controllers/search.js.coffee
@@ -0,0 +1,54 @@
+$ = jQuery.sub()
+
+class Search extends Spine.Controller
+
+ @isSearch = false
+
+ @resetSearch: ->
+ if Search.isSearch == true
+ Search.isSearch = false
+ $("#search_box").val('')
+ Message.fetch()
+
+ constructor: ->
+ $("#search_form").live('submit', @searchSubmit)
+ Sidebar.bind 'joinedRoom', Search.resetSearch
+
+ @render()
+
+ template: ->
+ @view('rooms/search')()
+
+ searchSubmit: (e) =>
+ e.preventDefault()
+ @search($("#search_box").val())
+
+ search: (q) ->
+ console.log(q == '')
+ if q == null || q == ''
+ Search.isSearch = false
+ Message.deleteAll()
+ Message.fetch()
+ return
+
+ Search.isSearch = true
+ $.get '/api/search/', { query: q, ns: "[room]#{Sidebar.room().id}" }, (data) =>
+ if data.length > 0
+ Message.deleteAll()
+
+ for message in data
+ Spine.Ajax.disable =>
+ Message.create(
+ body: message.body
+ username: message.username
+ room_id: message.room_id
+ )
+
+ Message.trigger 'refresh'
+ else
+ alert 'No messages found'
+
+ render: =>
+ $("#room_search").html @template()
+
+window.Search = Search
View
2  speakeasy_vaudeville/app/assets/javascripts/app/index.js.coffee
@@ -21,6 +21,7 @@ class App extends Spine.Controller
"#online": "onlineEl"
".invites": "invitesEl"
"#room-info": "roomInfoEl"
+ "#room_search": 'searchEl'
constructor: ->
super
@@ -32,6 +33,7 @@ class App extends Spine.Controller
@sidebar = new Sidebar({el: @sidebarEl})
@messages = new Messages({el: @messagesEl})
@room_info = new RoomInfo({el: @roomInfoEl})
+ @search = new Search({ el: @searchEl})
@inviter = new Inviter({el: @invitesEl})
# Spine.Route.setup
View
29 speakeasy_vaudeville/app/assets/javascripts/app/models/faye.js.coffee
@@ -11,7 +11,7 @@ class FayeHandler extends Spine.Module
@publishLeftRoom()
@url:
- "#{window.location.host.replace(':9000', '')}:9292/faye"
+ "#{window.location.host.replace(':9000', '').replace(':9001', '')}:9292/faye"
publishToRoom: (room, msg) =>
@faye.publish "/room/#{room.id}", msg
@@ -33,22 +33,25 @@ class FayeHandler extends Spine.Module
subscribeToRoom: (room) =>
if not @connected[room.id]
@faye.subscribe "/room/#{room.id}/joined", (msg) =>
- Spine.Ajax.disable =>
- @joinedRoom(msg)
+ if Search.isSearch == false
+ Spine.Ajax.disable =>
+ @joinedRoom(msg)
@faye.subscribe "/room/#{room.id}/left", (msg) =>
- Spine.Ajax.disable =>
- @leftRoom(msg)
+ if Search.isSearch == false
+ Spine.Ajax.disable =>
+ @leftRoom(msg)
@faye.subscribe "/room/#{room.id}", (msg) =>
- Spine.Ajax.disable =>
- msg = Message.create(
- body: msg.body,
- room_id: msg.room_id,
- username: msg.username
- )
-
- @connected[room.id] = true
+ if Search.isSearch == false
+ Spine.Ajax.disable =>
+ msg = Message.create(
+ body: msg.body,
+ room_id: msg.room_id,
+ username: msg.username
+ )
+
+ @connected[room.id] = true
subscribeToRooms: =>
@rooms = Room.all()
View
4 speakeasy_vaudeville/app/assets/javascripts/app/views/rooms/search.jst.eco
@@ -0,0 +1,4 @@
+<form id='search_form'>
+ <input type='text' id='search_box' />
+ <input type='submit' value='Go' />
+</form>
View
5 speakeasy_vaudeville/app/views/app/index.html.erb
@@ -78,6 +78,11 @@
</div>
<img id="ci_status" src="https://secure.travis-ci.org/jcasimir/draper.png"></img>
<div id="data">
+ <div class='header'>
+ <h4>Search</h4>
+ <div id='room_search'>
+ </div>
+ </div>
<div class="github header">
<h4>Github Activity</h4>
</div>
Please sign in to comment.
Something went wrong with that request. Please try again.