FIX: Re-enable searching for topic by id when using the split topic
interface.
This commit is contained in:
parent
b5b13b8c5f
commit
8a6c4234fc
|
@ -23,6 +23,7 @@ Discourse.Search = {
|
||||||
// Only include the data we have
|
// Only include the data we have
|
||||||
var data = { term: term };
|
var data = { term: term };
|
||||||
if (opts.typeFilter) data.type_filter = opts.typeFilter;
|
if (opts.typeFilter) data.type_filter = opts.typeFilter;
|
||||||
|
if (opts.searchForId) data.search_for_id = true;
|
||||||
|
|
||||||
if (opts.searchContext) {
|
if (opts.searchContext) {
|
||||||
data.search_context = {
|
data.search_context = {
|
||||||
|
|
|
@ -30,7 +30,7 @@ export default Discourse.View.extend({
|
||||||
self.setProperties({ topics: null, loading: false });
|
self.setProperties({ topics: null, loading: false });
|
||||||
return;
|
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) {
|
if (facets && facets[0] && facets[0].results) {
|
||||||
self.set('topics', facets[0].results);
|
self.set('topics', facets[0].results);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -14,6 +14,7 @@ class SearchController < ApplicationController
|
||||||
if params[:include_blurbs].present?
|
if params[:include_blurbs].present?
|
||||||
search_args[:include_blurbs] = params[:include_blurbs] == "true"
|
search_args[:include_blurbs] = params[:include_blurbs] == "true"
|
||||||
end
|
end
|
||||||
|
search_args[:search_for_id] = true if params[:search_for_id].present?
|
||||||
|
|
||||||
search_context = params[:search_context]
|
search_context = params[:search_context]
|
||||||
if search_context.present?
|
if search_context.present?
|
||||||
|
|
|
@ -111,7 +111,8 @@ class Search
|
||||||
return nil if @term.blank? || @term.length < (@opts[:min_search_term_length] || SiteSetting.min_search_term_length)
|
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 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
|
begin
|
||||||
route = Rails.application.routes.recognize_path(@term)
|
route = Rails.application.routes.recognize_path(@term)
|
||||||
return single_topic(route[:topic_id]).as_json if route[:topic_id].present?
|
return single_topic(route[:topic_id]).as_json if route[:topic_id].present?
|
||||||
|
|
|
@ -191,8 +191,18 @@ describe Search do
|
||||||
end
|
end
|
||||||
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
|
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
|
it 'returns the topic' do
|
||||||
result.should be_present
|
result.should be_present
|
||||||
|
|
|
@ -4,11 +4,15 @@ describe SearchController do
|
||||||
|
|
||||||
let(:search_context) { {type: 'user', id: 'eviltrout'} }
|
let(:search_context) { {type: 'user', id: 'eviltrout'} }
|
||||||
|
|
||||||
it 'performs the query' do
|
context "basics" do
|
||||||
guardian = Guardian.new
|
let(:guardian) { Guardian.new }
|
||||||
Guardian.stubs(:new).returns(guardian)
|
let(:search) { mock() }
|
||||||
|
|
||||||
search = mock()
|
before do
|
||||||
|
Guardian.stubs(:new).returns(guardian)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'performs the query' do
|
||||||
Search.expects(:new).with('test', guardian: guardian).returns(search)
|
Search.expects(:new).with('test', guardian: guardian).returns(search)
|
||||||
search.expects(:execute)
|
search.expects(:execute)
|
||||||
|
|
||||||
|
@ -16,10 +20,6 @@ describe SearchController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'performs the query with a filter' do
|
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(:new).with('test', guardian: guardian, type_filter: 'topic').returns(search)
|
||||||
search.expects(:execute)
|
search.expects(:execute)
|
||||||
|
|
||||||
|
@ -27,16 +27,21 @@ describe SearchController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "performs the query and returns results including blurbs" do
|
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(:new).with('test', guardian: guardian, include_blurbs: true).returns(search)
|
||||||
search.expects(:execute)
|
search.expects(:execute)
|
||||||
|
|
||||||
xhr :get, :query, term: 'test', include_blurbs: 'true'
|
xhr :get, :query, term: 'test', include_blurbs: 'true'
|
||||||
end
|
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
|
||||||
|
|
||||||
|
|
||||||
context "search context" do
|
context "search context" do
|
||||||
|
|
||||||
it "raises an error with an invalid context type" do
|
it "raises an error with an invalid context type" do
|
||||||
|
|
Loading…
Reference in New Issue