/wiki_pages: sort autocomplete by post count.

* Add search[order]=post_count param to /wiki_pages.
* Make autocomplete do a prefix match ordered by post count, so that it
  works the same way that tag autocomplete does elsewhere.
This commit is contained in:
evazion
2017-03-30 13:14:57 -05:00
parent 6b462c865e
commit b9693827c3
4 changed files with 11 additions and 5 deletions

View File

@@ -20,8 +20,9 @@
$.ajax({ $.ajax({
url: "/wiki_pages.json", url: "/wiki_pages.json",
data: { data: {
"search[title]": "*" + req.term + "*", "search[title]": req.term + "*",
"search[hide_deleted]": "Yes", "search[hide_deleted]": "Yes",
"search[order]": "post_count",
"limit": 10 "limit": 10
}, },
method: "get", method: "get",

View File

@@ -15,7 +15,7 @@ class WikiPagesController < ApplicationController
end end
def index def index
@wiki_pages = WikiPage.search(params[:search]).order("updated_at desc").paginate(params[:page], :limit => params[:limit], :search_count => params[:search]) @wiki_pages = WikiPage.search(params[:search]).paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
respond_with(@wiki_pages) do |format| respond_with(@wiki_pages) do |format|
format.html do format.html do
if params[:page].nil? || params[:page].to_i == 1 if params[:page].nil? || params[:page].to_i == 1

View File

@@ -79,10 +79,15 @@ class WikiPage < ActiveRecord::Base
end end
params[:order] ||= params.delete(:sort) params[:order] ||= params.delete(:sort)
if params[:order] == "time" || params[:order] == "Date" case params[:order]
when "time"
q = q.order("updated_at desc") q = q.order("updated_at desc")
elsif params[:order] == "title" || params[:order] == "Name" when "title"
q = q.order("title") q = q.order("title")
when "post_count"
q = q.joins(:tag).order("tags.post_count desc")
else
q = q.order("updated_at desc")
end end
q q

View File

@@ -13,7 +13,7 @@
<div class="input"> <div class="input">
<label for="search_order">Order</label> <label for="search_order">Order</label>
<%= select "search", "order", ["Name", "Date"] %> <%= select "search", "order", [%w[Name title], %w[Date time], %w[Posts post_count]] %>
</div> </div>
<div class="input"> <div class="input">