X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/51ed55cc32580644544b8e38c570bbfdaf09b5a2..13dbeb75c77ae88984cfe2730a4c9a1561304564:/settings/flex-base.lua diff --git a/settings/flex-base.lua b/settings/flex-base.lua index d91299ad..fe3ce32a 100644 --- a/settings/flex-base.lua +++ b/settings/flex-base.lua @@ -219,49 +219,58 @@ function tag_match(data) return nil end - local tests = {} + local fullmatches = {} + local key_prefixes = {} + local key_suffixes = {} if data.keys ~= nil then for _, key in pairs(data.keys) do if key:sub(1, 1) == '*' then if #key > 1 then - local suffix = key:sub(2) - tests[#tests + 1] = function (k, v) - return k:sub(-#suffix) == suffix + if key_suffixes[#key - 1] == nil then + key_suffixes[#key - 1] = {} end + key_suffixes[#key - 1][key:sub(2)] = true end elseif key:sub(#key, #key) == '*' then - local prefix = key:sub(1, #key - 1) - tests[#tests + 1] = function (k, v) - return k:sub(1, #prefix) == prefix + if key_prefixes[#key - 1] == nil then + key_prefixes[#key - 1] = {} end + key_prefixes[#key - 1][key:sub(1, #key - 1)] = true else - tests[#tests + 1] = function (k, v) - return k == key - end + fullmatches[key] = true end end end if data.tags ~= nil then - local tags = {} for k, vlist in pairs(data.tags) do - tags[k] = {} - for _, v in pairs(vlist) do - tags[k][v] = true + if fullmatches[k] == nil then + fullmatches[k] = {} + for _, v in pairs(vlist) do + fullmatches[k][v] = true + end end end - tests[#tests + 1] = function (k, v) - return tags[k] ~= nil and tags[k][v] ~= nil - end end return function (k, v) - for _, func in pairs(tests) do - if func(k, v) then + if fullmatches[k] ~= nil and (fullmatches[k] == true or fullmatches[k][v] ~= nil) then + return true + end + + for slen, slist in pairs(key_suffixes) do + if #k >= slen and slist[k:sub(-slen)] ~= nil then + return true + end + end + + for slen, slist in pairs(key_prefixes) do + if #k >= slen and slist[k:sub(1, slen)] ~= nil then return true end end + return false end end @@ -322,8 +331,10 @@ function process_tags(o) end -- address keys - o:grab_address{match=function (k, v) return COUNTRY_TAGS(k, v) and #v == 2 end, - out_key='country'} + o:grab_address{match=COUNTRY_TAGS, out_key='country'} + if o.address.country ~= nil and #o.address.country ~= 2 then + o.address['country'] = nil + end if o:grab_name{match=HOUSENAME_TAGS} > 0 then fallback = {'place', 'house'} end @@ -336,16 +347,6 @@ function process_tags(o) local is_interpolation = o:grab_address{match=INTERPOLATION_TAGS} > 0 - if ADD_TIGER_COUNTY then - local v = o:grab_tag('tiger:county') - if v ~= nil then - v, num = v:gsub(',.*', ' county') - if num == 0 then - v = v .. ' county' - end - o:set_address('tiger:county', v) - end - end o:grab_address{match=ADDRESS_TAGS} if is_interpolation then