mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
add search filter
This commit is contained in:
parent
b2d6e2aa43
commit
90d7718103
3 changed files with 20 additions and 3 deletions
|
@ -269,7 +269,8 @@ class ListController < ApplicationController
|
||||||
ascending: params[:ascending],
|
ascending: params[:ascending],
|
||||||
min_posts: params[:min_posts],
|
min_posts: params[:min_posts],
|
||||||
max_posts: params[:max_posts],
|
max_posts: params[:max_posts],
|
||||||
status: params[:status]
|
status: params[:status],
|
||||||
|
search: params[:search]
|
||||||
}
|
}
|
||||||
options[:no_subcategories] = true if params[:no_subcategories] == 'true'
|
options[:no_subcategories] = true if params[:no_subcategories] == 'true'
|
||||||
|
|
||||||
|
|
|
@ -232,10 +232,20 @@ class Search
|
||||||
posts.limit(limit)
|
posts.limit(limit)
|
||||||
end
|
end
|
||||||
|
|
||||||
def query_locale
|
def self.query_locale
|
||||||
@query_locale ||= Post.sanitize(Search.long_locale)
|
@query_locale ||= Post.sanitize(Search.long_locale)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def query_locale
|
||||||
|
self.class.query_locale
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.ts_query(term)
|
||||||
|
all_terms = term.gsub(/[:()&!'"]/,'').split
|
||||||
|
query = Post.sanitize(all_terms.map {|t| "#{PG::Connection.escape_string(t)}:*"}.join(" & "))
|
||||||
|
"TO_TSQUERY(#{query_locale}, #{query})"
|
||||||
|
end
|
||||||
|
|
||||||
def ts_query
|
def ts_query
|
||||||
@ts_query ||= begin
|
@ts_query ||= begin
|
||||||
all_terms = @term.gsub(/[:()&!'"]/,'').split
|
all_terms = @term.gsub(/[:()&!'"]/,'').split
|
||||||
|
|
|
@ -22,7 +22,9 @@ class TopicQuery
|
||||||
ascending
|
ascending
|
||||||
no_subcategories
|
no_subcategories
|
||||||
no_definitions
|
no_definitions
|
||||||
status).map(&:to_sym)
|
status
|
||||||
|
search
|
||||||
|
).map(&:to_sym)
|
||||||
|
|
||||||
# Maps `order` to a columns in `topics`
|
# Maps `order` to a columns in `topics`
|
||||||
SORTABLE_MAPPING = {
|
SORTABLE_MAPPING = {
|
||||||
|
@ -259,6 +261,10 @@ class TopicQuery
|
||||||
result = result.where('topics.id in (?)', options[:topic_ids]).references(:topics)
|
result = result.where('topics.id in (?)', options[:topic_ids]).references(:topics)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if search = options[:search]
|
||||||
|
result = result.where("topics.id in (select pp.topic_id from post_search_data pd join posts pp on pp.id = pd.post_id where pd.search_data @@ #{Search.ts_query(search.to_s)})")
|
||||||
|
end
|
||||||
|
|
||||||
if status = options[:status]
|
if status = options[:status]
|
||||||
case status
|
case status
|
||||||
when 'open'
|
when 'open'
|
||||||
|
|
Loading…
Reference in a new issue