[nautilus/gnome-3-8] query: rank prefix matches lower than exact matches



commit 8d0ae533c01fc785c097329f2e7f9a3faf686b6d
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Thu Apr 4 17:59:31 2013 -0400

    query: rank prefix matches lower than exact matches
    
    Count how many letters are left after the string occurrence, and
    subtract that from the match score.

 libnautilus-private/nautilus-query.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/libnautilus-private/nautilus-query.c b/libnautilus-private/nautilus-query.c
index 1393cd0..f282b0c 100644
--- a/libnautilus-private/nautilus-query.c
+++ b/libnautilus-private/nautilus-query.c
@@ -96,7 +96,7 @@ nautilus_query_matches_string (NautilusQuery *query,
        gchar *prepared_string, *ptr;
        gboolean found;
        gdouble retval;
-       gint idx;
+       gint idx, nonexact_malus;
 
        if (!query->details->text) {
                return -1;
@@ -111,12 +111,15 @@ nautilus_query_matches_string (NautilusQuery *query,
        prepared_string = prepare_string_for_compare (string);
        found = TRUE;
        ptr = NULL;
+       nonexact_malus = 0;
 
        for (idx = 0; query->details->prepared_words[idx] != NULL; idx++) {
                if ((ptr = strstr (prepared_string, query->details->prepared_words[idx])) == NULL) {
                        found = FALSE;
                        break;
                }
+
+               nonexact_malus += strlen (ptr) - strlen (query->details->prepared_words[idx]);
        }
 
        if (!found) {
@@ -124,7 +127,7 @@ nautilus_query_matches_string (NautilusQuery *query,
                return -1;
        }
 
-       retval = MAX (10.0, (50.0 / idx) - (gdouble) (ptr - prepared_string));
+       retval = MAX (10.0, 50.0 - (gdouble) (ptr - prepared_string) - nonexact_malus);
        g_free (prepared_string);
 
        return retval;


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