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"
14 #define INDEX_VERSION (0x32240100+sizeof(struct card_attr)) /* Increase with each incompatible change in index format */
17 * Words and word complexes
19 * MAX_WORD_LEN is the maximum length (measured in UTF-8 characters, excluding
20 * the terminating zero byte if there's any) of any word which may appear in the
21 * indices or in the bucket file. Naturally, the same constant also bounds
22 * the number of UCS-2 characters in a word.
24 * Caveat: If you are upcasing/downcasing the word, the UTF-8 encoding can
25 * expand, although at most twice, so you need to reserve 2*MAX_WORD_LEN bytes.
27 * MAX_COMPLEX_LEN is the upper bound on number of words in any word complex.
30 #define MAX_WORD_LEN 64 /* a multiple of 4 */
31 #define MAX_COMPLEX_LEN 10
33 /* Word and string types are defined in lib/custom.h */
35 /* Index card attributes */
38 u32 card; /* Reference to card description (either oid or filepos) */
42 CUSTOM_CARD_ATTRS /* Include all custom attributes */
46 byte age; /* Document age in pseudo-logarithmic units wrt. reference time */
48 #ifdef CONFIG_FILETYPE
49 byte type_flags; /* File type flags (see below) */
54 CARD_FLAG_EMPTY = 1, /* Empty document (redirect, robot file etc.) [scanner] */
55 CARD_FLAG_ACCENTED = 2, /* Document contains accented characters [scanner] */
56 CARD_FLAG_DUP = 4, /* Removed as a duplicate [merger] */
57 CARD_FLAG_MERGED = 8, /* Destination of a merge [merger] */
58 CARD_FLAG_IMAGE = 16, /* Is an image object [scanner] */
59 CARD_FLAG_FRAMESET = 32, /* Contains a frameset to be ignored [scanner] */
60 CARD_FLAG_GIANT_CLASS = 64, /* Belongs to a very large class, subject to penalties [merger] */
63 #define CARD_POS_SHIFT 5 /* Card positions are shifted this # of bits to the right */
66 * We store document type and several other properties in card_attr->type_flags.
67 * Here we define only the basic structure, the details are defined in custom.h
68 * (the list of type names custom_file_type_names[] and also setting of the file
69 * types in custom_create_attrs()).
71 * bits 7--5 file type: (0-3: text types, 4-7: other types, defined by custom.h)
72 * bits 4--0 type-dependent information, for text types it's document language code
75 #ifdef CONFIG_FILETYPE
76 #define CA_GET_FILE_TYPE(a) ((a)->type_flags >> 5)
77 #define CA_GET_FILE_INFO(a) ((a)->type_flags & 0x1f)
78 #define CA_GET_FILE_LANG(a) ((a)->type_flags & 0x80 ? 0 : CA_GET_FILE_INFO(a))
79 #define FILETYPE_ATTRS SMALL_SET_ATTR(ftype, FILETYPE, CA_GET_FILE_TYPE, ext_ft_parse)
80 #define MAX_FILE_TYPES 8
81 byte *ext_ft_parse(u32 *dest, byte *value, uns intval);
82 extern byte *custom_file_type_names[MAX_FILE_TYPES];
84 #define FILETYPE_ATTRS
88 /* You can use language matching without CONFIG_FILETYPE, but you have to define CA_GET_FILE_LANG yourself. */
89 #define LANG_ATTRS SMALL_SET_ATTR(lang, LANG, CA_GET_FILE_LANG, ext_lang_parse)
90 byte *ext_lang_parse(u32 *dest, byte *value, uns intval);
95 #define EXTENDED_ATTRS CUSTOM_ATTRS LANG_ATTRS /* Beware, FILETYPE_ATTRS are handled separately */
97 /* String fingerprints */
103 void fingerprint(byte *string, struct fingerprint *fp);
106 fp_hash(struct fingerprint *fp)
108 return fp->hash[0] ^ fp->hash[1] ^ fp->hash[2] ^ fp->hash[3];
111 /* Reading of tagged text (Unicode values, tags mapped to 0x80000000 and higher) */
113 #define GET_TAGGED_CHAR(p,u) do { \
116 GET_UTF8_CHAR(p,u); \
117 else if (u >= 0x80) \
125 else if (u >= 0xa0) \
127 ASSERT(*p >= 0x80 && *p <= 0xbf); \
128 u = 0x80010000 + ((u & 0x0f) << 6) + (*p++ & 0x3f); \
137 #define SKIP_TAGGED_CHAR(p) do { \
138 if (*p >= 0x80 && *p < 0xc0) \
141 if (u >= 0xa0 && u < 0xb0 && *p >= 0x80 && *p < 0xc0) \
149 bget_tagged_char(struct fastbuf *f)
164 ASSERT(v >= 0x80 && v <= 0xbf);
165 u = 0x80010000 + ((u & 0x0f) << 6) + (v & 0x3f);
178 /* Conversion of document age from seconds to our internal units */
181 convert_age(sh_time_t lastmod, sh_time_t reftime)
184 if (reftime < lastmod) /* past times */
186 age = (reftime - lastmod) / 3600;
187 if (age < 48) /* last 2 days: 1 hour resolution */
190 if (age < 64) /* next 64 days: 1 day resolution */
193 if (age < 135) /* next 135 weeks: 1 week resolution */
195 age = (age-135) / 52;
196 if (age < 8) /* next 8 years: 1 year resolution */
198 return 255; /* then just "infinite future" */