]> the.earth.li Git - onak.git/commitdiff
Fix fetching key by text bug in db4 backend
authorJonathan McDowell <noodles@earth.li>
Fri, 16 May 2008 17:59:04 +0000 (18:59 +0100)
committerJonathan McDowell <noodles@earth.li>
Fri, 16 May 2008 17:59:04 +0000 (18:59 +0100)
  We don't want to add keys when there are no keys in the previous list,
  we want to only add new keys on the first pass. Otherwise if we end up
  with an empty list we'll start again as if none of the previous words
  where specified.

keydb_db4.c

index 7f6404c492558501239290b53c3b29b5b29c354d..85aeab559e9c60a7f6300401d176bfd6c19f5ee7 100644 (file)
@@ -475,6 +475,7 @@ static int db4_fetch_key_text(const char *search,
        struct ll *curword = NULL;
        struct keyarray keylist = { NULL, 0, 0 };
        struct keyarray newkeylist = { NULL, 0, 0 };
+       int firstpass = 1;
 
        numkeys = 0;
        searchtext = strdup(search);
@@ -507,8 +508,12 @@ static int db4_fetch_key_text(const char *search,
                                                data.data)[i];
                        }
 
-                       if (keylist.count == 0 ||
-                                       array_find(&keylist, keyid)) {
+                       /*
+                        * Only add the keys containing this word if this is
+                        * our first pass (ie we have no existing key list),
+                        * or the key contained a previous word.
+                        */
+                       if (firstpass || array_find(&keylist, keyid)) {
                                array_add(&newkeylist, keyid);
                        }
 
@@ -530,6 +535,7 @@ static int db4_fetch_key_text(const char *search,
                }
                ret = cursor->c_close(cursor);
                cursor = NULL;
+               firstpass = 0;
                db4_endtrans();
        }
        llfree(wordlist, NULL);