diff options
author | Cosimo Cecchi <cosimoc@gnome.org> | 2013-04-04 17:59:31 -0400 |
---|---|---|
committer | Cosimo Cecchi <cosimoc@gnome.org> | 2013-04-15 18:42:40 -0400 |
commit | 8d0ae533c01fc785c097329f2e7f9a3faf686b6d (patch) | |
tree | 3b90d2c1e4598e21c46d8fd3e6c1b3f883cc1071 | |
parent | 9e7ca2a860d2eeaecec30c04518a92c8da957216 (diff) | |
download | nautilus-8d0ae533c01fc785c097329f2e7f9a3faf686b6d.tar.gz |
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.
-rw-r--r-- | libnautilus-private/nautilus-query.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/libnautilus-private/nautilus-query.c b/libnautilus-private/nautilus-query.c index 1393cd07a..f282b0c8c 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; |