2 * Sherlock: Data structures used in indices
4 * (c) 2001--2003 Martin Mares <mj@ucw.cz>
7 #ifndef _SHERLOCK_INDEX_H
8 #define _SHERLOCK_INDEX_H
10 #include "lib/fastbuf.h"
11 #include SHERLOCK_CUSTOM
12 #include "charset/unistream.h"
15 * Words and word complexes
17 * MAX_WORD_LEN is the maximum length (measured in UTF-8 characters, excluding
18 * the terminating zero byte if there's any) of any word which may appear in the
19 * indices or in the bucket file. Naturally, the same constant also bounds
20 * the number of UCS-2 characters in a word.
22 * Caveat: If you are upcasing/downcasing the word, the UTF-8 encoding can
23 * expand, although at most twice, so you need to reserve 2*MAX_WORD_LEN bytes.
25 * MAX_COMPLEX_LEN is the upper bound on number of words in any word complex.
28 #define MAX_WORD_LEN 64 /* a multiple of 4 */
29 #define MAX_COMPLEX_LEN 10
31 /* Word and string types are defined in lib/custom.h */
33 /* Global index parameters */
36 sh_time_t ref_time; /* Reference time (for document ages etc.) */
39 /* Index card attributes */
42 u32 card; /* Reference to card description (either oid or filepos) */
46 CUSTOM_CARD_ATTRS /* Include all custom attributes */
50 byte age; /* Document age in pseudo-logarithmic units wrt. reference time */
52 #ifdef CONFIG_FILETYPE
53 byte type_flags; /* File type flags (see below) */
58 CARD_FLAG_EMPTY = 1, /* Empty document (redirect, robot file etc.) [scanner] */
59 CARD_FLAG_ACCENTED = 2, /* Document contains accented characters [scanner] */
60 CARD_FLAG_DUP = 4, /* Removed as a duplicate [merger] */
61 CARD_FLAG_MERGED = 8, /* Destination of a merge [merger] */
62 CARD_FLAG_IMAGE = 16, /* Is an image object [scanner] */
63 CARD_FLAG_FRAMESET = 32, /* Contains a frameset [scanner] */
66 #define CARD_POS_SHIFT 5 /* Card positions are shifted this # of bits to the right */
69 * We store document type and several other properties in card_attr->type_flags.
70 * Here we define only the basic structure, the details and also how to match the
71 * types are defined in custom.h.
73 * bits 7--5 file type: (0-3: text types, 4-7: other types, defined by custom.h)
74 * bits 4--0 type-dependent information, for text types it's document language code
77 #define CA_GET_FILE_TYPE(a) ((a)->type_flags >> 5)
78 #define CA_GET_FILE_INFO(a) ((a)->type_flags & 0x1f)
79 #define CA_GET_FILE_LANG(a) ((a)->type_flags & 0x80 ? 0 : CA_GET_FILE_INFO(a))
81 /* String fingerprints */
87 void fingerprint(byte *string, struct fingerprint *fp);
90 fp_hash(struct fingerprint *fp)
92 return (fp->hash[0] << 24) | (fp->hash[1] << 16) | (fp->hash[2] << 8) | fp->hash[3];
95 /* Reading of tagged text (Unicode values, tags mapped to 0x80000000 and higher) */
97 #define GET_TAGGED_CHAR(p,u) do { \
100 GET_UTF8_CHAR(p,u); \
101 else if (u >= 0x80) \
109 else if (u >= 0xa0) \
111 ASSERT(*p >= 0x80 && *p <= 0xbf); \
112 u = 0x80010000 + ((u & 0x0f) << 6) + (*p++ & 0x3f); \
121 #define SKIP_TAGGED_CHAR(p) do { \
122 if (*p >= 0x80 && *p < 0xc0) \
125 if (u >= 0xa0 && u < 0xb0 && *p >= 0x80 && *p < 0xc0) \
133 bget_tagged_char(struct fastbuf *f)
148 ASSERT(v >= 0x80 && v <= 0xbf);
149 u = 0x80010000 + ((u & 0x0f) << 6) + (v & 0x3f);
162 /* Conversion of document age from seconds to our internal units */
165 convert_age(sh_time_t lastmod, sh_time_t reftime)
168 if (reftime < lastmod) /* past times */
170 age = (reftime - lastmod) / 3600;
171 if (age < 48) /* last 2 days: 1 hour resolution */
174 if (age < 64) /* next 64 days: 1 day resolution */
177 if (age < 135) /* next 135 weeks: 1 week resolution */
179 age = (age-135) / 52;
180 if (age < 8) /* next 8 years: 1 year resolution */
182 return 255; /* then just "infinite future" */