FIX: Re-enable searching for topic by id when using the split topic

interface.
This commit is contained in:
Robin Ward 2014-08-28 15:42:29 -04:00
parent b5b13b8c5f
commit 8a6c4234fc
6 changed files with 49 additions and 31 deletions

View File

@ -23,6 +23,7 @@ Discourse.Search = {
// Only include the data we have
var data = { term: term };
if (opts.typeFilter) data.type_filter = opts.typeFilter;
if (opts.searchForId) data.search_for_id = true;
if (opts.searchContext) {
data.search_context = {

View File

@ -30,7 +30,7 @@ export default Discourse.View.extend({
self.setProperties({ topics: null, loading: false });
return;
}
Discourse.Search.forTerm(title, {typeFilter: 'topic'}).then(function (facets) {
Discourse.Search.forTerm(title, {typeFilter: 'topic', searchForId: true}).then(function (facets) {
if (facets && facets[0] && facets[0].results) {
self.set('topics', facets[0].results);
} else {

View File

@ -14,6 +14,7 @@ class SearchController < ApplicationController
if params[:include_blurbs].present?
search_args[:include_blurbs] = params[:include_blurbs] == "true"
end
search_args[:search_for_id] = true if params[:search_for_id].present?
search_context = params[:search_context]
if search_context.present?

View File

@ -111,7 +111,8 @@ class Search
return nil if @term.blank? || @term.length < (@opts[:min_search_term_length] || SiteSetting.min_search_term_length)
# If the term is a number or url to a topic, just include that topic
if @results.type_filter == 'topic'
if @opts[:search_for_id] && @results.type_filter == 'topic'
return single_topic(@term.to_i).as_json if @term =~ /^\d+$/
begin
route = Rails.application.routes.recognize_path(@term)
return single_topic(route[:topic_id]).as_json if route[:topic_id].present?

View File

@ -191,8 +191,18 @@ describe Search do
end
end
context "search for a topic by id" do
let(:result) { first_of_type(Search.new(topic.id, type_filter: 'topic', search_for_id: true, min_search_term_length: 1).execute, 'topic') }
it 'returns the topic' do
result.should be_present
result[:title].should == topic.title
result[:url].should == topic.relative_url
end
end
context "search for a topic by url" do
let(:result) { first_of_type(Search.new(topic.relative_url, type_filter: 'topic').execute, 'topic') }
let(:result) { first_of_type(Search.new(topic.relative_url, search_for_id: true, type_filter: 'topic').execute, 'topic') }
it 'returns the topic' do
result.should be_present

View File

@ -4,38 +4,43 @@ describe SearchController do
let(:search_context) { {type: 'user', id: 'eviltrout'} }
it 'performs the query' do
guardian = Guardian.new
Guardian.stubs(:new).returns(guardian)
context "basics" do
let(:guardian) { Guardian.new }
let(:search) { mock() }
search = mock()
Search.expects(:new).with('test', guardian: guardian).returns(search)
search.expects(:execute)
before do
Guardian.stubs(:new).returns(guardian)
end
xhr :get, :query, term: 'test'
it 'performs the query' do
Search.expects(:new).with('test', guardian: guardian).returns(search)
search.expects(:execute)
xhr :get, :query, term: 'test'
end
it 'performs the query with a filter' do
Search.expects(:new).with('test', guardian: guardian, type_filter: 'topic').returns(search)
search.expects(:execute)
xhr :get, :query, term: 'test', type_filter: 'topic'
end
it "performs the query and returns results including blurbs" do
Search.expects(:new).with('test', guardian: guardian, include_blurbs: true).returns(search)
search.expects(:execute)
xhr :get, :query, term: 'test', include_blurbs: 'true'
end
it 'performs the query with a filter and passes through search_for_id' do
Search.expects(:new).with('test', guardian: guardian, search_for_id: true, type_filter: 'topic').returns(search)
search.expects(:execute)
xhr :get, :query, term: 'test', type_filter: 'topic', search_for_id: true
end
end
it 'performs the query with a filter' do
guardian = Guardian.new
Guardian.stubs(:new).returns(guardian)
search = mock()
Search.expects(:new).with('test', guardian: guardian, type_filter: 'topic').returns(search)
search.expects(:execute)
xhr :get, :query, term: 'test', type_filter: 'topic'
end
it "performs the query and returns results including blurbs" do
guardian = Guardian.new
Guardian.stubs(:new).returns(guardian)
search = mock()
Search.expects(:new).with('test', guardian: guardian, include_blurbs: true).returns(search)
search.expects(:execute)
xhr :get, :query, term: 'test', include_blurbs: 'true'
end
context "search context" do