diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 136b30d..c90123a 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -516,6 +516,7 @@ li .domain { color: #888; font-style: italic; font-size: 8.5pt; + text-decoration: none; vertical-align: middle; } diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 94d48fd..3251b74 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -7,9 +7,13 @@ class SearchController < ApplicationController if params[:q].to_s.present? @search.q = params[:q].to_s - @search.what = params[:what] - @search.order = params[:order] + if params[:what].present? + @search.what = params[:what] + end + if params[:order].present? + @search.order = params[:order] + end if params[:page].present? @search.page = params[:page].to_i end diff --git a/app/indices/story_index.rb b/app/indices/story_index.rb index 45eb64f..5e62e34 100644 --- a/app/indices/story_index.rb +++ b/app/indices/story_index.rb @@ -11,6 +11,10 @@ ThinkingSphinx::Index.define :story, :with => :active_record do has hotness, is_expired has Story.score_sql, :as => :score, :type => :bigint, :sortable => true + # opts[:with] = { :id => ... } doesn't seem to work when sphinx searches on + # story_core, so give this column a different name to restrict on + has id, :as => :story_id + set_property :field_weights => { :upvotes => 15, :title => 10, diff --git a/app/models/search.rb b/app/models/search.rb index e6fa2a3..67f9456 100644 --- a/app/models/search.rb +++ b/app/models/search.rb @@ -58,6 +58,30 @@ class Search opts[:order] = "score DESC" end + # extract domain query since it must be done separately + domain = nil + words = self.q.to_s.split(" ").reject{|w| + if m = w.match(/^domain:(.+)$/) + domain = m[1] + end + }.join(" ") + + if domain.present? + self.what = "stories" + story_ids = Story.select(:id).where("`url` REGEXP '//([^/]*\.)?" + + ActiveRecord::Base.connection.quote_string(domain) + "/'"). + collect(&:id) + + if story_ids.any? + opts[:with] = { :story_id => story_ids } + else + self.results = [] + self.total_results = 0 + self.page = 0 + return false + end + end + opts[:classes] = case what when "all" [ Story, Comment ] @@ -70,7 +94,7 @@ class Search end # escape sphinx special chars (using Riddle.escape removes boolean support) - query = self.q.gsub(/([\/~"])/, '\\\\\1') + query = words.gsub(/([\/~"])/, '\\\\\1') # go go gadget search self.results = [] diff --git a/app/models/story.rb b/app/models/story.rb index 7eab9df..60188e9 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -227,6 +227,10 @@ class Story < ActiveRecord::Base end end + def domain_search_url + "/search?q=domain:#{self.domain}&order=newest" + end + def fetch_story_cache! if self.url.present? self.story_cache = StoryCacher.get_story_text(self.url) diff --git a/app/views/stories/_listdetail.html.erb b/app/views/stories/_listdetail.html.erb index 89e63be..4b6e0d0 100644 --- a/app/views/stories/_listdetail.html.erb +++ b/app/views/stories/_listdetail.html.erb @@ -29,7 +29,10 @@ class="story <%= story.vote == 1 ? "upvoted" : "" %> <%= story.vote == -1 ? title="<%= tagging.tag.description %>"><%= tagging.tag.tag %> <% end %> - <%= story.domain %> + <% if story.domain.present? %> + <%= + story.domain %> + <% end %> <% if defined?(single_story) && single_story %> <% story.merged_stories.each do |ms| %> @@ -45,7 +48,10 @@ class="story <%= story.vote == 1 ? "upvoted" : "" %> <%= story.vote == -1 ? title="<%= tagging.tag.description %>"><%= tagging.tag.tag %> <% end %> - <%= ms.domain %> + <% if ms.domain.present? %> + <%= + ms.domain %> + <% end %> by