From 815be8f27fe362f9c63889735cac89053ed8c51a Mon Sep 17 00:00:00 2001 From: Dennis Schafroth Date: Fri, 13 Apr 2012 13:15:32 +0200 Subject: [PATCH] Using approximation for sorting in version 2 --- src/session.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/session.c b/src/session.c index 36be061..76b43fe 100644 --- a/src/session.c +++ b/src/session.c @@ -1015,6 +1015,14 @@ static int cmp_ht(const void *p1, const void *p2) return h2->hits - h1->hits; } +// Compares two hitsbytarget nodes by hitcount +static int cmp_ht_approx(const void *p1, const void *p2) +{ + const struct hitsbytarget *h1 = p1; + const struct hitsbytarget *h2 = p2; + return h2->approximation - h1->approximation; +} + static int targets_termlist_nb(WRBUF wrbuf, struct session *se, int num, NMEM nmem, int version) { @@ -1022,7 +1030,10 @@ static int targets_termlist_nb(WRBUF wrbuf, struct session *se, int num, int count, i; ht = hitsbytarget_nb(se, &count, nmem); - qsort(ht, count, sizeof(struct hitsbytarget), cmp_ht); + if (version >= 2) + qsort(ht, count, sizeof(struct hitsbytarget), cmp_ht_approx); + else + qsort(ht, count, sizeof(struct hitsbytarget), cmp_ht); for (i = 0; i < count && i < num && ht[i].hits > 0; i++) { -- 1.7.10.4