summaryrefslogtreecommitdiff
path: root/web/lib/api/v4/search.rb
diff options
context:
space:
mode:
Diffstat (limited to 'web/lib/api/v4/search.rb')
-rw-r--r--web/lib/api/v4/search.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/web/lib/api/v4/search.rb b/web/lib/api/v4/search.rb
index cf8d5e1..edc2710 100644
--- a/web/lib/api/v4/search.rb
+++ b/web/lib/api/v4/search.rb
@@ -84,6 +84,47 @@ class Taginfo < Sinatra::Base
}.to_json
end
+ api(4, 'search/by_role', {
+ :description => 'Search for relation roles.',
+ :parameters => { :query => 'Role to search for (substring search, required).' },
+ :sort => %w( count_all rtype role ),
+ :paging => :optional,
+ :result => paging_results([
+ [:rtype, :STRING, 'Relation type.'],
+ [:role, :STRING, 'Role'],
+ [:count_all, :INT, 'Number of objects in the database with this role.']
+ ]),
+ :example => { :query => 'foo', :page => 1, :rp => 10 },
+ :ui => '/search?q=foo#roles'
+ }) do
+ query = params[:query]
+
+ total = @db.count('db.relation_roles').
+ condition_if("role LIKE '%' || ? || '%'", query).
+ get_first_value().to_i
+
+ res = @db.select('SELECT * FROM db.relation_roles').
+ condition_if("role LIKE '%' || ? || '%'", query).
+ order_by(@ap.sortname, @ap.sortorder) { |o|
+ o.count_all
+ o.rtype
+ o.role
+ }.
+ paging(@ap).
+ execute()
+
+ return {
+ :page => @ap.page,
+ :rp => @ap.results_per_page,
+ :total => total,
+ :data => res.map{ |row| {
+ :rtype => row['rtype'],
+ :role => row['role'],
+ :count_all => row['count_all'].to_i,
+ }}
+ }.to_json
+ end
+
api(4, 'search/by_value', {
:description => 'Search for tags by value.',
:parameters => { :query => 'Value to search for (substring search, required).' },