diff options
author | Cosimo Cecchi <cosimoc@gnome.org> | 2013-04-04 17:59:31 -0400 |
---|---|---|
committer | Cosimo Cecchi <cosimoc@gnome.org> | 2013-04-04 20:13:31 -0400 |
commit | 9f2d8a519a42aa33ea05e99910632b628586978a (patch) | |
tree | 59532ab09023fb4a11f8544c82a98ea296f56d32 /libnautilus-private/nautilus-query.c | |
parent | e55a3feb941112426a1298f4beb420100031f5de (diff) | |
download | nautilus-9f2d8a519a42aa33ea05e99910632b628586978a.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.
Diffstat (limited to 'libnautilus-private/nautilus-query.c')
-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; |