2 * Sherlock: Data structures used in indices
4 * (c) 2001--2004 Martin Mares <mj@ucw.cz>
7 #ifndef _SHERLOCK_INDEX_H
8 #define _SHERLOCK_INDEX_H
10 #include "custom/lib/custom.h"
12 #define INDEX_VERSION (0x32260200+sizeof(struct card_attr)) /* Increase with each incompatible change in index format */
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.
26 #define MAX_WORD_LEN 64 /* a multiple of 4 */
28 /* Word and string types are defined in lib/custom.h */
30 /* Types used for storing contexts */
32 #ifdef CONFIG_CONTEXTS
33 #if CONFIG_MAX_CONTEXTS == 32768
34 typedef u16 context_t;
35 #define bget_context bgetw
36 #define bput_context bputw
37 #define GET_CONTEXT GET_U16
38 #define PUT_CONTEXT PUT_U16
39 #elif CONFIG_MAX_CONTEXTS == 256
40 typedef byte context_t;
41 #define bget_context bgetc
42 #define bput_context bputc
43 #define GET_CONTEXT GET_U8
44 #define PUT_CONTEXT PUT_U8
46 #error CONFIG_MAX_CONTEXTS set to an invalid value.
50 typedef struct { } context_t;
51 static inline uns bget_context(struct fastbuf *b UNUSED) { return 0; }
52 static inline void bput_context(struct fastbuf *b UNUSED, uns context UNUSED) { }
53 #define GET_CONTEXT(p) 0
54 #define PUT_CONTEXT(p,x) do {} while(0)
57 /* Index card attributes */
60 u32 card; /* Reference to card description (either oid or filepos) */
64 CUSTOM_CARD_ATTRS /* Include all custom attributes */
68 byte age; /* Document age in pseudo-logarithmic units wrt. reference time */
70 #ifdef CONFIG_FILETYPE
71 byte type_flags; /* File type flags (see below) */
76 CARD_FLAG_EMPTY = 1, /* Empty document (redirect, robot file etc.) [scanner] */
77 CARD_FLAG_ACCENTED = 2, /* Document contains accented characters [scanner] */
78 CARD_FLAG_DUP = 4, /* Removed as a duplicate [merger] */
79 CARD_FLAG_MERGED = 8, /* Destination of a merge [merger] */
80 CARD_FLAG_IMAGE = 16, /* Is an image object [scanner] */
81 CARD_FLAG_FRAMESET = 32, /* Contains a frameset to be ignored [scanner] */
82 CARD_FLAG_OVERRIDEN = 64, /* Overriden by another index [sherlockd] */
85 #define CARD_POS_SHIFT 5 /* Card positions are shifted this # of bits to the right */
88 * We store document type and several other properties in card_attr->type_flags.
89 * Here we define only the basic structure, the details are defined in custom.h
90 * (the list of type names custom_file_type_names[] and also setting of the file
91 * types in custom_create_attrs()).
93 * bits 7--5 file type: (0-3: text types, 4-7: other types, defined by custom.h)
94 * bits 4--0 type-dependent information, for text types it's document language code
97 #ifdef CONFIG_FILETYPE
98 #define CA_GET_FILE_TYPE(a) ((a)->type_flags >> 5)
99 #define CA_GET_FILE_INFO(a) ((a)->type_flags & 0x1f)
100 #define CA_GET_FILE_LANG(a) ((a)->type_flags & 0x80 ? 0 : CA_GET_FILE_INFO(a))
101 #define FILETYPE_ATTRS SMALL_SET_ATTR(ftype, FILETYPE, CA_GET_FILE_TYPE, ext_ft_parse)
102 #define MAX_FILE_TYPES 8
103 #define FILETYPE_IS_TEXT(f) ((f) < 4)
104 byte *ext_ft_parse(u32 *dest, byte *value, uns intval);
105 extern byte *custom_file_type_names[MAX_FILE_TYPES];
107 #define FILETYPE_ATTRS
111 /* You can use language matching without CONFIG_FILETYPE, but you have to define CA_GET_FILE_LANG yourself. */
112 #define LANG_ATTRS SMALL_SET_ATTR(lang, LANG, CA_GET_FILE_LANG, ext_lang_parse)
113 byte *ext_lang_parse(u32 *dest, byte *value, uns intval);
118 #define EXTENDED_ATTRS CUSTOM_ATTRS LANG_ATTRS /* Beware, FILETYPE_ATTRS are handled separately */
120 /* String fingerprints */
126 void fingerprint(byte *string, struct fingerprint *fp);
129 fp_hash(struct fingerprint *fp)
131 return (fp->hash[0] << 24) | (fp->hash[1] << 16) | (fp->hash[2] << 8) | fp->hash[3];
134 /* The card fingerprints */
137 struct fingerprint fp;
143 #define URL_KEY_BUF_SIZE (3*MAX_URL_SIZE)
144 byte *url_key(byte *url, byte *buf);
145 void url_fingerprint(byte *url, struct fingerprint *fp);
146 void url_key_init(void);
148 /* Conversion of document age from seconds to our internal units */
151 convert_age(sh_time_t lastmod, sh_time_t reftime)
154 if (reftime < lastmod) /* past times */
156 age = (reftime - lastmod) / 3600;
157 if (age < 48) /* last 2 days: 1 hour resolution */
160 if (age < 64) /* next 64 days: 1 day resolution */
163 if (age < 135) /* next 135 weeks: 1 week resolution */
165 age = (age-135) / 52;
166 if (age < 8) /* next 8 years: 1 year resolution */
168 return 255; /* then just "infinite future" */