From: Martin Mares Date: Sat, 20 Apr 2002 18:20:04 +0000 (+0000) Subject: Forgot to commit this one during the "search by age" changes. X-Git-Tag: holmes-import~1439 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=8ffdaed1c5f5bf4ad0914b8d17f14af51ce037a5;p=libucw.git Forgot to commit this one during the "search by age" changes. --- diff --git a/lib/index.h b/lib/index.h index 6a22cf17..05851412 100644 --- a/lib/index.h +++ b/lib/index.h @@ -10,6 +10,12 @@ /* Word and string types are defined in lib/custom.h */ +/* Global index parameters */ + +struct index_params { + sh_time_t ref_time; /* Reference time (for document ages etc.) */ +}; + /* Index card attributes */ struct card_attr { @@ -20,7 +26,8 @@ struct card_attr { #undef INT_ATTR byte weight; byte flags; - // byte rfu[2]; /* If no custom attributes are defined */ + byte age; /* Document age in pseudo-logarithmic units wrt. reference time */ + // byte rfu[1]; /* If no custom attributes are defined */ }; enum card_flag { @@ -72,3 +79,26 @@ fp_hash(struct fingerprint *fp) else \ p++; \ } while (0) + +/* Conversion of document age from seconds to our internal units */ + +static inline int +convert_age(sh_time_t lastmod, sh_time_t reftime) +{ + sh_time_t age; + if (reftime < lastmod) /* past times */ + return -1; + age = (reftime - lastmod) / 3600; + if (age < 48) /* last 2 days: 1 hour resolution */ + return age; + age = (age-48) / 24; + if (age < 64) /* next 64 days: 1 day resolution */ + return 48 + age; + age = (age-64) / 7; + if (age < 135) /* next 135 weeks: 1 week resolution */ + return 112 + age; + age = (age-135) / 52; + if (age < 8) /* next 8 years: 1 year resolution */ + return 247 + age; + return 255; /* then just "infinite future" */ +}