Search rank using discourse-solved plugin


(Helperhaps) #1

Hi there ,
I am using the discourse-solved plugin. And I would like to have this feather, topic which has been marked solved have the high rank when searching, that means if the searching result has the solved topic, it will be displayed more front that before.

Dig into the plugin, I found the result’s order is decided by the followed code

# lib/search.rb:530
posts = posts.order("TS_RANK_CD(TO_TSVECTOR(#{query_locale}, topics.title), #{ts_query}) DESC")

data_ranking = "TS_RANK_CD(post_search_data.search_data, #{ts_query})"
if opts[:aggregate_search]
  posts = posts.order("SUM(#{data_ranking}) DESC")
else
  posts = posts.order("#{data_ranking} DESC")
end
posts = posts.order("topics.bumped_at DESC")

But the solved mark is stored in custom_fields, i can read it with topic.custom_fields[:accepted_answer_post_id] or post.custom_fields[:is_accepted_answer]

How could i make this into sql query expression? Or else what can i do ?


(Sam Saffron) #2

Its an interesting request but currently there is no easy way of adding that feature.


(Helperhaps) #3

It seems i have make myself understood. But i can not find where custom_fileds stores :joy:

U said it is not easy. Is it becouse SQL can not query with data stored in custom_fileds?


(Sam Saffron) #4

The query is not the hard part, the hard part is hooking it in from the plugin in a clean way