summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--web/lib/api/db.rb18
-rw-r--r--web/public/js/taginfo.js3
2 files changed, 15 insertions, 6 deletions
diff --git a/web/lib/api/db.rb b/web/lib/api/db.rb
index 82cf48c..3a3de71 100644
--- a/web/lib/api/db.rb
+++ b/web/lib/api/db.rb
@@ -193,7 +193,7 @@ class Taginfo < Sinatra::Base
end
api(2, 'db/keys/distribution', {
- :description => 'Get map with distribution of this key in the database.',
+ :description => 'Get map with distribution of this key in the database (nodes only).',
:parameters => { :key => 'Tag key (required).' },
:result => 'PNG image.',
:example => { :key => 'amenity' },
@@ -311,7 +311,10 @@ class Taginfo < Sinatra::Base
api(2, 'db/keys/keys', {
:description => 'Find keys that are used together with a given key.',
- :parameters => { :key => 'Tag key (required).' },
+ :parameters => {
+ :key => 'Tag key (required).',
+ :query => 'Only show results where the other_key matches this query (substring match, optional).'
+ },
:paging => :optional,
:filter => {
:all => { :doc => 'No filter.' },
@@ -338,8 +341,8 @@ class Taginfo < Sinatra::Base
params[:sortname] = ['from_fraction', 'together_count', 'other_key']
end
- total = @db.count('db.keypairs').
- condition('key1 = ? OR key2 = ?', key, key).
+ cq = @db.count('db.keypairs')
+ total = (params[:query] != '' ? cq.condition("(key1 = ? AND key2 LIKE '%' || ? || '%') OR (key2 = ? AND key1 LIKE '%' || ? || '%')", key, params[:query], key, params[:query]) : cq.condition('key1 = ? OR key2 = ?', key, key)).
condition("count_#{filter_type} > 0").
get_first_value().to_i
@@ -347,8 +350,11 @@ class Taginfo < Sinatra::Base
condition('key = ?', key).
get_first_value()
- res = @db.select("SELECT p.key1 AS other_key, p.count_#{filter_type} AS together_count, k.count_#{filter_type} AS other_count, CAST(p.count_#{filter_type} AS REAL) / k.count_#{filter_type} AS from_fraction FROM db.keypairs p, db.keys k WHERE p.key1=k.key AND p.key2=? AND p.count_#{filter_type} > 0
- UNION SELECT p.key2 AS other_key, p.count_#{filter_type} AS together_count, k.count_#{filter_type} AS other_count, CAST(p.count_#{filter_type} AS REAL) / k.count_#{filter_type} AS from_fraction FROM db.keypairs p, db.keys k WHERE p.key2=k.key AND p.key1=? AND p.count_#{filter_type} > 0", key, key).
+ res = (params[:query] != '' ?
+ @db.select("SELECT p.key1 AS other_key, p.count_#{filter_type} AS together_count, k.count_#{filter_type} AS other_count, CAST(p.count_#{filter_type} AS REAL) / k.count_#{filter_type} AS from_fraction FROM db.keypairs p, db.keys k WHERE p.key1=k.key AND p.key2=? AND (p.key1 LIKE '%' || ? || '%') AND p.count_#{filter_type} > 0
+ UNION SELECT p.key2 AS other_key, p.count_#{filter_type} AS together_count, k.count_#{filter_type} AS other_count, CAST(p.count_#{filter_type} AS REAL) / k.count_#{filter_type} AS from_fraction FROM db.keypairs p, db.keys k WHERE p.key2=k.key AND p.key1=? AND (p.key2 LIKE '%' || ? || '%') AND p.count_#{filter_type} > 0", key, params[:query], key, params[:query]) :
+ @db.select("SELECT p.key1 AS other_key, p.count_#{filter_type} AS together_count, k.count_#{filter_type} AS other_count, CAST(p.count_#{filter_type} AS REAL) / k.count_#{filter_type} AS from_fraction FROM db.keypairs p, db.keys k WHERE p.key1=k.key AND p.key2=? AND p.count_#{filter_type} > 0
+ UNION SELECT p.key2 AS other_key, p.count_#{filter_type} AS together_count, k.count_#{filter_type} AS other_count, CAST(p.count_#{filter_type} AS REAL) / k.count_#{filter_type} AS from_fraction FROM db.keypairs p, db.keys k WHERE p.key2=k.key AND p.key1=? AND p.count_#{filter_type} > 0", key, key)).
order_by(params[:sortname], params[:sortorder]){ |o|
o.together_count
o.other_key
diff --git a/web/public/js/taginfo.js b/web/public/js/taginfo.js
index 1c56f53..c7956d2 100644
--- a/web/public/js/taginfo.js
+++ b/web/public/js/taginfo.js
@@ -406,6 +406,9 @@ var create_flexigrid_for = {
{ display: '<span title="Key used together with this key">Other key</span>', name: 'other_key', width: 340, sortable: true },
{ display: '<span title="Number of objects with other key that also have this key">&rarr; Count</span>', name: 'from_count', width: 320, sortable: true, align: 'center' }
],
+ searchitems: [
+ { display: 'Other key', name: 'other_key' }
+ ],
sortname: 'to_count',
sortorder: 'desc',
height: 410,