[geocode-glib/wip/issue-9] forward: Equality for missing attributes in result



commit c40f7981a50d1d6cce655fa673208cec2c856463
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Mon Jan 13 12:21:48 2014 +0100

    forward: Equality for missing attributes in result
    
    The function insert_place_into_tree creates a GNode
    based tree that is built up by the search results attributes.
    The idea is that if places share attributes they share a path
    and we can later minimize what we include in the name.
    
    This patch fixes a bug where missing attributes where inserted
    as completly new nodes, creating subtrees that could never get
    siblings.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=721340
    
    Closes: #9

 geocode-glib/geocode-nominatim.c | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)
---
diff --git a/geocode-glib/geocode-nominatim.c b/geocode-glib/geocode-nominatim.c
index fc333dc..15c426a 100644
--- a/geocode-glib/geocode-nominatim.c
+++ b/geocode-glib/geocode-nominatim.c
@@ -510,23 +510,22 @@ insert_place_into_tree (GNode *place_tree, GHashTable *ht)
                GNode *child = NULL;
 
                attr_val = g_hash_table_lookup (ht, place_attributes[i]);
-               if (!attr_val) {
-                       /* Add a dummy node if the attribute value is not
-                        * available for the place */
-                       child = g_node_insert_data (start, -1, NULL);
-               } else {
-                       /* If the attr value (eg for country United States)
-                        * already exists, then keep on adding other attributes under that node. */
-                       child = g_node_first_child (start);
-                       while (child &&
-                              child->data &&
-                              g_ascii_strcasecmp (child->data, attr_val) != 0) {
-                               child = g_node_next_sibling (child);
-                       }
-                       if (!child) {
-                               /* create a new node */
-                               child = g_node_insert_data (start, -1, g_strdup (attr_val));
+               /* If the attr value (eg for country United States or missing completely)
+                * already exists, then keep on adding other attributes under that node. */
+               child = g_node_first_child (start);
+               while (child) {
+                       if (!attr_val) {
+                               if (!child->data)
+                                       break;
+                       } else if (child->data) {
+                               if (g_ascii_strcasecmp (child->data, attr_val) == 0)
+                                       break;
                        }
+                       child = g_node_next_sibling (child);
+               }
+               if (!child) {
+                       /* create a new node */
+                       child = g_node_insert_data (start, -1, g_strdup (attr_val));
                }
                start = child;
        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]