From a1244043d37e05669473441d5360aac1acbec7e0 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 28 Aug 2014 17:15:53 +1000 Subject: [PATCH] FIX: when search finds a deep link in a topic it takes you to it --- app/controllers/search_controller.rb | 2 +- lib/search.rb | 13 ++++++++----- spec/components/search_spec.rb | 12 +----------- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index f3e00c16b07..bcf0e7fe9d5 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -8,7 +8,7 @@ class SearchController < ApplicationController def query params.require(:term) - + search_args = {guardian: guardian} search_args[:type_filter] = params[:type_filter] if params[:type_filter].present? if params[:include_blurbs].present? diff --git a/lib/search.rb b/lib/search.rb index 7d3c167c08e..0be363c47fc 100644 --- a/lib/search.rb +++ b/lib/search.rb @@ -279,13 +279,16 @@ class Search def aggregate_search cols = ['topics.id', 'topics.title', 'topics.slug'] - topics = posts_query(@limit, aggregate_search: true).group(*cols).pluck(*cols) + topics = posts_query(@limit, aggregate_search: true) + .group(*cols) + .pluck('min(posts.post_number)',*cols) + topics.each do |t| @results.add_result(SearchResult.new(type: :topic, - topic_id: t[0], - id: t[0], - title: t[1], - url: "/t/#{t[2]}/#{t[0]}")) + topic_id: t[1], + id: t[1], + title: t[2], + url: "/t/#{t[3]}/#{t[1]}/#{t[0]}")) end end diff --git a/spec/components/search_spec.rb b/spec/components/search_spec.rb index 29b4ce20b56..3fb68152e67 100644 --- a/spec/components/search_spec.rb +++ b/spec/components/search_spec.rb @@ -110,17 +110,8 @@ describe Search do it 'returns a result' do result.should be_present - end - - it 'has the display name as the title' do result[:title].should == user.username - end - - it 'has the avatar_template is there so it can hand it to the client' do result[:avatar_template].should_not be_nil - end - - it 'has a url for the record' do result[:url].should == "/users/#{user.username_lower}" end @@ -196,8 +187,7 @@ describe Search do result.should be_present result[:title].should == topic.title - # The link is to the topic url because it's aggregated - result[:url].should == topic.relative_url + result[:url].should == topic.relative_url + "/2" end end