allow searching stories by domain, link domain in story list to such a query
This commit is contained in:
parent
00d347c4f4
commit
a16150d8a5
|
@ -516,6 +516,7 @@ li .domain {
|
||||||
color: #888;
|
color: #888;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
font-size: 8.5pt;
|
font-size: 8.5pt;
|
||||||
|
text-decoration: none;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,13 @@ class SearchController < ApplicationController
|
||||||
|
|
||||||
if params[:q].to_s.present?
|
if params[:q].to_s.present?
|
||||||
@search.q = params[:q].to_s
|
@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?
|
if params[:page].present?
|
||||||
@search.page = params[:page].to_i
|
@search.page = params[:page].to_i
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,6 +11,10 @@ ThinkingSphinx::Index.define :story, :with => :active_record do
|
||||||
has hotness, is_expired
|
has hotness, is_expired
|
||||||
has Story.score_sql, :as => :score, :type => :bigint, :sortable => true
|
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 => {
|
set_property :field_weights => {
|
||||||
:upvotes => 15,
|
:upvotes => 15,
|
||||||
:title => 10,
|
:title => 10,
|
||||||
|
|
|
@ -58,6 +58,30 @@ class Search
|
||||||
opts[:order] = "score DESC"
|
opts[:order] = "score DESC"
|
||||||
end
|
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
|
opts[:classes] = case what
|
||||||
when "all"
|
when "all"
|
||||||
[ Story, Comment ]
|
[ Story, Comment ]
|
||||||
|
@ -70,7 +94,7 @@ class Search
|
||||||
end
|
end
|
||||||
|
|
||||||
# escape sphinx special chars (using Riddle.escape removes boolean support)
|
# escape sphinx special chars (using Riddle.escape removes boolean support)
|
||||||
query = self.q.gsub(/([\/~"])/, '\\\\\1')
|
query = words.gsub(/([\/~"])/, '\\\\\1')
|
||||||
|
|
||||||
# go go gadget search
|
# go go gadget search
|
||||||
self.results = []
|
self.results = []
|
||||||
|
|
|
@ -227,6 +227,10 @@ class Story < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def domain_search_url
|
||||||
|
"/search?q=domain:#{self.domain}&order=newest"
|
||||||
|
end
|
||||||
|
|
||||||
def fetch_story_cache!
|
def fetch_story_cache!
|
||||||
if self.url.present?
|
if self.url.present?
|
||||||
self.story_cache = StoryCacher.get_story_text(self.url)
|
self.story_cache = StoryCacher.get_story_text(self.url)
|
||||||
|
|
|
@ -29,7 +29,10 @@ class="story <%= story.vote == 1 ? "upvoted" : "" %> <%= story.vote == -1 ?
|
||||||
title="<%= tagging.tag.description %>"><%= tagging.tag.tag %></a>
|
title="<%= tagging.tag.description %>"><%= tagging.tag.tag %></a>
|
||||||
<% end %>
|
<% end %>
|
||||||
</span>
|
</span>
|
||||||
<span class="domain"><%= story.domain %></span>
|
<% if story.domain.present? %>
|
||||||
|
<a class="domain" href="<%= story.domain_search_url %>"><%=
|
||||||
|
story.domain %></a>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<% if defined?(single_story) && single_story %>
|
<% if defined?(single_story) && single_story %>
|
||||||
<% story.merged_stories.each do |ms| %>
|
<% 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 %></a>
|
title="<%= tagging.tag.description %>"><%= tagging.tag.tag %></a>
|
||||||
<% end %>
|
<% end %>
|
||||||
</span>
|
</span>
|
||||||
<span class="domain"><%= ms.domain %></span>
|
<% if ms.domain.present? %>
|
||||||
|
<a class="domain" href="<%= ms.domain_search_url %>"><%=
|
||||||
|
ms.domain %></a>
|
||||||
|
<% end %>
|
||||||
<span class="byline">
|
<span class="byline">
|
||||||
by <a href="/u/<%= ms.user.username %>"
|
by <a href="/u/<%= ms.user.username %>"
|
||||||
<% if ms.user.is_new? %>
|
<% if ms.user.is_new? %>
|
||||||
|
|
Loading…
Reference in a new issue