Order search results by importance of address parts

This is an attempt to resolve the issue with result ordering when administrative entities of different levels share the same name.

This has two parts:

  * make sure that results with exact name matches float on top when scanning search_name
  * compute a combined importance from the address parts of each result and use that as secondary feature for result ordering

It can be tested here: http://poldi.osm.org/lonvia/search

Second part seems to work fairly well for the problematic results I know of, e.g
http://nominatim.osm.org/search.php?q=dlouh%C3%A1%2C+praha vs.
http://poldi.osm.org/lonvia/search.php?q=dlouh%C3%A1%2C+praha

It also helps for boosting the better known city in cases like this:
http://nominatim.osm.org/search.php?q=james+st%2C+london vs.
http://poldi.osm.org/lonvia/search.php?q=james+st%2C+london

The first part (exact name matches) gets mixed results because it depends on the fact that the name of the less important entity gets prefixed. Works here:

http://nominatim.osm.org/search?q=lessingstr%2C+stuttgart vs. 
http://poldi.osm.org/lonvia/search?q=lessingstr%2C+stuttgart

but doesn't help here (because the county node is called 'Karlsruhe' not the usual 'Landkreis Karlsruhe':

http://nominatim.osm.org/search?q=lessingstr%2C+karlsruhe vs. 
http://poldi.osm.org/lonvia/search?q=lessingstr%2C+karlsruhe

I couldn't find too many examples where it helps, so I'm not convinced it is worth the trouble.

Any thoughts?