Permalink
Browse files

Updated Query to be more db agnostic, removed a bunch of files floati…

…ng around, updated docs for javascript
  • Loading branch information...
1 parent 1dc765b commit 5886130b7e79e8087cca6a4d65128322261f6c81 @cannikin cannikin committed Feb 3, 2009
View
3 app/controllers/search_controller.rb
@@ -8,7 +8,7 @@ class SearchController < ApplicationController
DO_RELATED_SEARCH = false # do all the related (ajax) searches for each and every result
# DO_CONTEXT_SEARCH = false # contextual search on the right
CONTEXT_RESULT_COUNT = 5 # number of items to show for contextual related
- MINI_RELEVANT_SEARCH_COUNT = 5 # number of results to show in the mini display of relevant results when the page is sorted by date
+ MINI_RELEVANT_SEARCH_COUNT = 3 # number of results to show in the mini display of relevant results when the page is sorted by date
DEFAULT_LOCATION = 'everywhere' # default location if geo-coding doesn't work
DEFAULT_SORT = 'relevance' # default sort method
SEARCH_MODES = [{:mode => 'activities', :name => 'Activities & Events' },
@@ -54,6 +54,7 @@ def index
google_sort_string = ''
end
+ # When these searches were threaded we seemed to be getting some inconsistent results...Rails not really threadsafe yet?
#threads = []
# if user is sorting by date, do another search by relevance for the top 5 result
View
3 app/models/override.rb
@@ -6,6 +6,9 @@
class Override < ActiveRecord::Base
self.inheritance_column = 'none'
+
+ validates_presence_of :keywords
+ validates_uniqueness_of :keywords
# Adding our own method for searching for a matching override since the logic is more complex than a standard find.
# We have some interesting logic here. Basically we take all overrides in the DB and then compare each one to the
View
78 app/models/query.rb
@@ -58,74 +58,68 @@ def update_with_options(params={}, values={})
# Top searches anywhere
def self.find_popular(num=5)
# select keywords, sum(`count`) as count from queries where location = 'San Diego, California' group by keywords order by count desc;
- find_by_sql(["select *, count(*) as total \
- from queries \
- where keywords != '' and created_at > '#{FIND_POPULAR_STARTING_ON}' \
- group by keywords, sport, type, custom \
- order by total desc \
- limit ?", num])
+ find(:all, :select => '*, count(*) as total',
+ :conditions => "keywords != '' and created_at > '#{FIND_POPULAR_STARTING_ON}'",
+ :group => "keywords, sport, type, custom",
+ :order => "total desc",
+ :limit => num)
end
# Top searches in the same location
def self.find_popular_by_mode(mode,num=5)
- find_by_sql(["select *, count(*) as total \
- from queries \
- where mode = ? and keywords != '' and keywords not like '%inmeta%' and keywords not like '%inurl%' and created_at > '#{FIND_POPULAR_STARTING_ON}' \
- group by keywords \
- order by total desc \
- limit ?", mode, num])
+ find(:all, :select => "*, count(*) as total",
+ :conditions => ["mode = ? and keywords != '' and keywords not like '%inmeta%' and keywords not like '%inurl%' and created_at > ?", mode, FIND_POPULAR_STARTING_ON],
+ :group => 'keywords',
+ :order => 'total desc',
+ :limit => num)
end
# Top searches in the same location
def self.find_popular_by_location(location,num=5)
- find_by_sql(["select *, count(*) as total \
- from queries \
- where location = ? and keywords != '' and keywords not like '%inmeta%' and keywords not like '%inurl%' and created_at > '#{FIND_POPULAR_STARTING_ON}' \
- group by keywords \
- order by total desc \
- limit ?", location.form_value, num])
+ find(:all, :select => "*, count(*) as total",
+ :conditions => ["location = ? and keywords != '' and keywords not like '%inmeta%' and keywords not like '%inurl%' and created_at > ?", location.form_value, FIND_POPULAR_STARTING_ON],
+ :group => 'keywords',
+ :order => 'total desc',
+ :limit => num)
end
# Top searches in the same location for this type of asset
def self.find_popular_by_location_and_mode(location,mode,num=5)
- find_by_sql(["select *, count(*) as total \
- from queries \
- where mode = ? and location = ? and keywords != '' and keywords not like '%inmeta%' and keywords not like '%inurl%' and created_at > '#{FIND_POPULAR_STARTING_ON}' \
- group by keywords \
- order by total desc \
- limit ?", mode, location.form_value, num])
+ find(:all, :select => "*, count(*) as total",
+ :conditions => ["mode = ? and location = ? and keywords != '' and keywords not like '%inmeta%' and keywords not like '%inurl%' and created_at > ?", mode, location.form_value, FIND_POPULAR_STARTING_ON],
+ :group => 'keywords',
+ :order => 'total desc',
+ :limit => num)
end
def self.find_related_by_mode(text,mode,num=5)
- find_by_sql(["select *, sum(count) as total \
- from queries \
- where mode = ? and keywords like ? and keywords not like '%inmeta%' and keywords not like '%inurl%' and keywords != ? and created_at > '#{FIND_POPULAR_STARTING_ON}' \
- group by keywords \
- order by total desc \
- limit ?", mode, "%#{text}%", text, num])
+ find(:all, :select => "*, sum(count) as total",
+ :conditions => ["mode = ? and keywords like ? and keywords not like '%inmeta%' and keywords not like '%inurl%' and keywords != ? and created_at > ?", mode, "%#{text}%", text, FIND_POPULAR_STARTING_ON],
+ :group => 'keywords',
+ :order => 'total desc',
+ :limit => num)
end
def self.find_related_by_location(text,location,num=5)
- find_by_sql(["select *, sum(count) as total \
- from queries \
- where location = ? and keywords like ? and keywords not like '%inmeta%' and keywords not like '%inurl%' and keywords != ? and created_at > '#{FIND_POPULAR_STARTING_ON}' \
- group by keywords \
- order by total desc \
- limit ?", location.form_value, "%#{text}%", text, num])
+ find(:all, :select => "*, sum(count) as total",
+ :conditions => ["mode = ? and keywords like ? and keywords not like '%inmeta%' and keywords not like '%inurl%' and keywords != ? and created_at > ?",location.form_value, "%#{text}%", text, FIND_POPULAR_STARTING_ON],
+ :group => 'keywords',
+ :order => 'total desc',
+ :limit => num)
end
+
# Top searches that contain some keyword in the same location
def self.find_related_by_location_and_mode(text,location,mode,num=5)
- find_by_sql(["select *, sum(count) as total \
- from queries \
- where mode = ? and location = ? and keywords like ? and keywords not like '%inmeta%' and keywords not like '%inurl%' and keywords != ? and created_at > '#{FIND_POPULAR_STARTING_ON}' \
- group by keywords \
- order by total desc \
- limit ?", mode, location.form_value, "%#{text}%", text, num])
+ find(:all, :select => "*, sum(count) as total",
+ :conditions => ["mode = ? and location = ? and keywords like ? and keywords not like '%inmeta%' and keywords not like '%inurl%' and keywords != ? and created_at > ?", mode, location.form_value, "%#{text}%", text, FIND_POPULAR_STARTING_ON],
+ :group => 'keywords',
+ :order => 'total desc',
+ :limit => num)
end
end
View
BIN app/views/search/.__featured.html.erb
Binary file not shown.
View
BIN app/views/search/._google.html.erb
Binary file not shown.
View
18 app/views/search/home.html.erb
@@ -1,36 +1,20 @@
<%= render :partial => 'search_modes', :locals => { :mode => @mode } %>
<form id="search_form" method="get" action="<%= url_for(:controller => 'search') %>">
- <!-- <%= render :partial => 'location', :locals => { :location => @location } %> -->
- <!--
- <input type="text" name="q" value="" onkeypress="return handleEnter(this.form, event);" />
- <input type="image" name="commit" src="/images/button_search_big.png" class="submit" />
- <div id="more_link"><a href="#" onclick="$('activity_search').toggle(); return false;">More Options</a></div>
- -->
<%= render :partial => "search/forms/#{@mode}", :layout => 'search/forms/layout', :locals => { :mode => @mode } %>
<script type="text/javascript">
// modify the formatting of the seraches a big so they look good on the homepage
$('debug_options') ? $('debug_options').hide() : null;
- $('search_location') ? $$('#search_form .submit').first().setStyle({top:'1.7em'}) : null; // move the search button down if there's a location bar
+ $('search_location') ? $$('#search_form .submit').first().setStyle({top:'1.3em'}) : null; // move the search button down if there's a location bar
$('start_date') ? $('start_date').value = 'today' : null;
if($('optional_search_fields')) {
$('optional_search_fields').hide();
$('keywords_container').insert({after:'<a id="more_link" href="#" onclick="$(\'optional_search_fields\').toggle(); return false;">More options</a>'});
}
</script>
- <!--
- <script type="text/javascript">
- // UGLY HACK COMING UP
- // remove the keywords and submit button from the activities search
- $('keywords_container').remove();
- $('commit').remove();
- $('start_date').value = 'today';
- </script>
- -->
-
</form>
<%= render :partial => 'popular_local_searches', :locals => { :location_text => @location.form_value } unless @popular_local_searches.empty?%>
View
4 app/views/search/index.html.erb
@@ -41,6 +41,10 @@
<!-- normal results -->
<%= render :partial => 'results', :locals => { :results => @google.results, :do_date_separators => @do_date_separators } %>
+ <script type="text/javascript">
+ var related = new Related(); // each result will fire an Ajax call back to the server to find related data, this guy handles the response from the server
+ </script>
+
<%# render :partial => 'add_activity_message' if @mode == 'activities' %>
<% if @google.total_results > GASOHOL_CONFIG[:google][:num] %>
View
BIN public/._.htaccess
Binary file not shown.
View
BIN public/._all_assets.xml
Binary file not shown.
View
BIN public/._assets.xml
Binary file not shown.
View
5 public/javascripts/application.js
@@ -29,6 +29,7 @@ Object.extend(CalendarDateSelect.prototype, {
});
+// append a sort parameter onto the URL when user clicks to change their sort
function sort(sort_by) {
var query_string = '?'
query_string += 'sort=' + sort_by;
@@ -54,10 +55,8 @@ function selectOption(obj, value) {
}
}
-// fire up an instance of the related items handler
-var related = new Related();
-// asset sports and types
+// asset sports and types (used by /javascripts/search.js)
var assets = [
{ text:'Any',
types: [
View
8 public/javascripts/search.js
@@ -1,3 +1,11 @@
+/*
+ This file is for building the sport/type dropdowns in the search filter area
+ When this class is instantiated you pass it an array of sport/type options and
+ they are automaticalled added and observed so as the user changes sport then
+ the type is automatically updated. See /javascripts/application.js for the list
+ of assets we pass into this
+*/
+
var Search = new Class.create();
Search.prototype = {

0 comments on commit 5886130

Please sign in to comment.