diff options
author | Jochen Topf <jochen@topf.org> | 2012-10-14 19:32:20 +0200 |
---|---|---|
committer | Jochen Topf <jochen@topf.org> | 2012-10-14 19:32:20 +0200 |
commit | 47eecdd35cac768566fc8a79afe7760bbf99b75a (patch) | |
tree | 9257beb7ee8e54b06121d7a7cdb931e92847e00d /web/lib | |
parent | d8296b1b2e916070e8de2c5435254d60e3b9bd3c (diff) | |
download | taginfo-47eecdd35cac768566fc8a79afe7760bbf99b75a.tar taginfo-47eecdd35cac768566fc8a79afe7760bbf99b75a.tar.gz |
Add minimal support for wiki pages fulltext search
Diffstat (limited to 'web/lib')
-rw-r--r-- | web/lib/api/search.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/web/lib/api/search.rb b/web/lib/api/search.rb index 2f0ef75..eca1ed8 100644 --- a/web/lib/api/search.rb +++ b/web/lib/api/search.rb @@ -78,4 +78,29 @@ class Taginfo < Sinatra::Base }.to_json end + api(2, 'search/wikipages') do + query = params[:q].downcase + + total = @db.count('wiki.words').condition("words LIKE ('%' || ? || '%')", query).get_first_value().to_i + sel = @db.select("SELECT key, value FROM wiki.words WHERE words LIKE ('%' || ? || '%')", query) + + res = sel. + order_by(params[:sortname], params[:sortorder]) { |o| + o.key + o.value + }. + paging(params[:rp], params[:page]). + execute() + + return { + :page => params[:page].to_i, + :rp => params[:rp].to_i, + :total => total, + :data => res.map{ |row| { + :key => row['key'], + :value => row['value'] + }} + }.to_json + end + end |