Skip to content

Commit

Permalink
Loads of bonerific Sphinx integration
Browse files Browse the repository at this point in the history
  • Loading branch information
jamierumbelow committed Nov 13, 2011
1 parent e5c5432 commit 9a913c8
Show file tree
Hide file tree
Showing 34 changed files with 147 additions and 12 deletions.
17 changes: 17 additions & 0 deletions app/assets/javascripts/home.js.coffee.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
$ ->
# Make an etherpad (test)
$("#padtest").pad
'host' : 'http://10.30.201.4:9001'
'padId' : 'test'
'userName' : $('body').attr 'data-current-user-name'

# Handle clever auto-searching
timer = false

$('#search input').keyup ->
clearTimeout(timer) if timer

timer = setTimeout =>
$.post RevisionHub.urls['searches_path'], { q: $(this).val() }, ( data, status, xhr ) ->
$('#results').html data
, 500
3 changes: 2 additions & 1 deletion app/controllers/searches_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
class SearchesController < ApplicationController
def create # POST /searches?q=Bath+Comp+Sci+CS101
results = ThinkingSphinx::Search.search params[:q], :classes => [ University, Course, Tag, Note ]
results = Note.search params[:q], :star => true

respond_to do |format|
format.json { render :json => results }
format.html
end
end
end
4 changes: 4 additions & 0 deletions app/models/course.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
class Course < ActiveRecord::Base
belongs_to :university
has_many :notes

define_indexes do
indexes :name
end
end
2 changes: 2 additions & 0 deletions app/models/note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class Note < ActiveRecord::Base

define_indexes do
indexes :title
indexes course.name, :as => :course_name
indexes course.university.name, :as => :university_name
end

def git_file_path
Expand Down
2 changes: 1 addition & 1 deletion app/models/university.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class University < ActiveRecord::Base
has_many :courses

define_index do
define_indexes do
indexes :name
end
end
16 changes: 7 additions & 9 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<form id="search" action="" method="GET">
<input class="title-text" type="text" name="query" size="10" maxlength="100"
title="Type in course name or whatever the hell you want..." />
</form>

<div id="results">


</div>
<form id="search" action="" method="GET">
<input class="defaultText title-text" type="text" name="query" size="10" maxlength="100" title="Type in course name, uni or any other search queries..." />
</form>

<div id="results">


</div>
10 changes: 9 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>Revisionhub</title>
<title>RevisionHub</title>
<%= stylesheet_link_tag "application" %>
<%= stylesheet_link_tag "reset" %>
<%= stylesheet_link_tag "screen" %>
Expand All @@ -10,6 +10,14 @@
<%= javascript_include_tag "application" %>
<%= javascript_include_tag "etherpad" %>
<%= csrf_meta_tags %>

<script type="text/javascript" charset="utf-8">
RevisionHub = {};
RevisionHub.urls = {
root_url: '<%= root_url %>',
searches_path: '<%= searches_path %>'
};
</script>
</head>
<%= user_data_attributes('body') %>
<p class="notice"><%= notice %></p>
Expand Down
Empty file.
101 changes: 101 additions & 0 deletions config/development.sphinx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
indexer
{
}

searchd
{
listen = 127.0.0.1:9312
log = /Users/jamierumbelow/Sites/revisionhub/revisionhub/log/searchd.log
query_log = /Users/jamierumbelow/Sites/revisionhub/revisionhub/log/searchd.query.log
pid_file = /Users/jamierumbelow/Sites/revisionhub/revisionhub/log/searchd.development.pid
}

source course_core_0
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = root
sql_db = revisionhub_development
sql_query_pre = SET NAMES utf8
sql_query_pre = SET TIME_ZONE = '+0:00'
sql_query = SELECT SQL_NO_CACHE `courses`.`id` * CAST(3 AS SIGNED) + 0 AS `id` , `courses`.`name` AS `name`, `courses`.`id` AS `sphinx_internal_id`, 0 AS `sphinx_deleted`, 288516751 AS `class_crc` FROM `courses` WHERE (`courses`.`id` >= $start AND `courses`.`id` <= $end) GROUP BY `courses`.`id` ORDER BY NULL
sql_query_range = SELECT IFNULL(MIN(`id`), 1), IFNULL(MAX(`id`), 1) FROM `courses`
sql_attr_uint = sphinx_internal_id
sql_attr_uint = sphinx_deleted
sql_attr_uint = class_crc
sql_query_info = SELECT * FROM `courses` WHERE `id` = (($id - 0) / 3)
}

index course_core
{
source = course_core_0
path = /Users/jamierumbelow/Sites/revisionhub/revisionhub/db/sphinx/development/course_core
charset_type = utf-8
}

index course
{
type = distributed
local = course_core
}

source tag_core_0
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = root
sql_db = revisionhub_development
sql_query_pre = SET NAMES utf8
sql_query_pre = SET TIME_ZONE = '+0:00'
sql_query = SELECT SQL_NO_CACHE `tags`.`id` * CAST(3 AS SIGNED) + 1 AS `id` , `tags`.`name` AS `name`, `tags`.`id` AS `sphinx_internal_id`, 0 AS `sphinx_deleted`, 1002762595 AS `class_crc` FROM `tags` WHERE (`tags`.`id` >= $start AND `tags`.`id` <= $end) GROUP BY `tags`.`id` ORDER BY NULL
sql_query_range = SELECT IFNULL(MIN(`id`), 1), IFNULL(MAX(`id`), 1) FROM `tags`
sql_attr_uint = sphinx_internal_id
sql_attr_uint = sphinx_deleted
sql_attr_uint = class_crc
sql_query_info = SELECT * FROM `tags` WHERE `id` = (($id - 1) / 3)
}

index tag_core
{
source = tag_core_0
path = /Users/jamierumbelow/Sites/revisionhub/revisionhub/db/sphinx/development/tag_core
charset_type = utf-8
}

index tag
{
type = distributed
local = tag_core
}

source university_core_0
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = root
sql_db = revisionhub_development
sql_query_pre = SET NAMES utf8
sql_query_pre = SET TIME_ZONE = '+0:00'
sql_query = SELECT SQL_NO_CACHE `universities`.`id` * CAST(3 AS SIGNED) + 2 AS `id` , `universities`.`name` AS `name`, `universities`.`id` AS `sphinx_internal_id`, 0 AS `sphinx_deleted`, 4012344892 AS `class_crc` FROM `universities` WHERE (`universities`.`id` >= $start AND `universities`.`id` <= $end) GROUP BY `universities`.`id` ORDER BY NULL
sql_query_range = SELECT IFNULL(MIN(`id`), 1), IFNULL(MAX(`id`), 1) FROM `universities`
sql_attr_uint = sphinx_internal_id
sql_attr_uint = sphinx_deleted
sql_attr_uint = class_crc
sql_query_info = SELECT * FROM `universities` WHERE `id` = (($id - 2) / 3)
}

index university_core
{
source = university_core_0
path = /Users/jamierumbelow/Sites/revisionhub/revisionhub/db/sphinx/development/university_core
charset_type = utf-8
}

index university
{
type = distributed
local = university_core
}
Binary file added db/sphinx/development/course_core.spa
Binary file not shown.
Binary file added db/sphinx/development/course_core.spd
Binary file not shown.
Binary file added db/sphinx/development/course_core.sph
Binary file not shown.
Binary file added db/sphinx/development/course_core.spi
Binary file not shown.
Empty file.
Empty file.
Empty file.
Binary file added db/sphinx/development/course_core.spp
Binary file not shown.
Empty file.
1 change: 1 addition & 0 deletions db/sphinx/development/tag_core.spd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Binary file added db/sphinx/development/tag_core.sph
Binary file not shown.
1 change: 1 addition & 0 deletions db/sphinx/development/tag_core.spi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions db/sphinx/development/tag_core.spp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Binary file added db/sphinx/development/university_core.spa
Binary file not shown.
Binary file added db/sphinx/development/university_core.spd
Binary file not shown.
Binary file added db/sphinx/development/university_core.sph
Binary file not shown.
Binary file added db/sphinx/development/university_core.spi
Binary file not shown.
Empty file.
Empty file.
Empty file.
Binary file added db/sphinx/development/university_core.spp
Binary file not shown.
1 change: 1 addition & 0 deletions log/searchd.development.pid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8399

0 comments on commit 9a913c8

Please sign in to comment.