[nautilus] query: prefer prefix matches over sufix matches
- From: Carlos Soriano <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] query: prefer prefix matches over sufix matches
- Date: Thu, 17 Aug 2017 13:56:45 +0000 (UTC)
commit a6d616e18dc46630d170d09fc84ac824de7d4fdf
Author: Alexandru Pandelea <alexandru pandelea gmail com>
Date: Thu Aug 10 14:52:57 2017 +0100
query: prefer prefix matches over sufix matches
Currently, the number of letters before and after the match decrease
the rank of the search hit by the same amount.
Though, the prefix matches should be prefered over the sufix ones,
so make the number of letters after the match decrease the rank
by a much smaller factor than the number of letters before the match.
https://bugzilla.gnome.org/show_bug.cgi?id=785942
src/nautilus-query.c | 11 ++++++++++-
1 files changed, 10 insertions(+), 1 deletions(-)
---
diff --git a/src/nautilus-query.c b/src/nautilus-query.c
index 53771ce..59600d1 100644
--- a/src/nautilus-query.c
+++ b/src/nautilus-query.c
@@ -31,6 +31,10 @@
#include "nautilus-query.h"
#include "nautilus-enum-types.h"
+#define RANK_SCALE_FACTOR 100
+#define MIN_RANK 10.0
+#define MAX_RANK 50.0
+
struct _NautilusQuery
{
GObject parent;
@@ -399,7 +403,12 @@ nautilus_query_matches_string (NautilusQuery *query,
return -1;
}
- retval = MAX (10.0, 50.0 - (gdouble) (ptr - prepared_string) - nonexact_malus);
+ /* The rank value depends on the numbers of letters before and after the match.
+ * To make the prefix matches prefered over sufix ones, the number of letters
+ * after the match is divided by a factor, so that it decreases the rank by a
+ * smaller amount.
+ */
+ retval = MAX (MIN_RANK, MAX_RANK - (gdouble) (ptr - prepared_string) - (gdouble) nonexact_malus /
RANK_SCALE_FACTOR);
g_free (prepared_string);
return retval;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]