[nautilus] query: rank prefix matches lower than exact matches
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] query: rank prefix matches lower than exact matches
- Date: Fri, 5 Apr 2013 00:20:06 +0000 (UTC)
commit 9f2d8a519a42aa33ea05e99910632b628586978a
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 files 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]