]> mj.ucw.cz Git - libucw.git/blob - lib/index.h
Removed old incarnation of CLAMP.
[libucw.git] / lib / index.h
1 /*
2  *      Sherlock Gatherer: Data structures used in indices
3  *
4  *      (c) 2001 Martin Mares <mj@ucw.cz>
5  */
6
7 /* Words */
8
9 #define MAX_WORD_LEN            64
10
11 /* Word types */
12
13 enum word_type {
14   WT_RESERVED,                          /* Reserved word type */
15   WT_TEXT,                              /* Ordinary text */
16   WT_EMPH,                              /* Emphasized text */
17   WT_SMALL,                             /* Small font */
18   WT_TITLE,                             /* Document title */
19   WT_SMALL_HEADING,                     /* Heading */
20   WT_BIG_HEADING,                       /* Larger heading */
21   WT_KEYWORD,                           /* Explicitly marked keyword */
22   WT_META,                              /* Various meta-information */
23   WT_ALT                                /* Alternate texts for graphical elements */
24 };
25
26 #define WORD_TYPE_NAMES                         \
27         T(WORD, ~0)                             \
28         T(TEXT, 1 << WT_TEXT)                   \
29         T(EMPH, 1 << WT_EMPH)                   \
30         T(SMALL, 1 << WT_SMALL)                 \
31         T(TITLE, 1 << WT_TITLE)                 \
32         T(HDR, (1 << WT_SMALL_HEADING) | (1 << WT_BIG_HEADING))  \
33         T(HDR1, 1 << WT_SMALL_HEADING)          \
34         T(HDR2, 1 << WT_BIG_HEADING)            \
35         T(KEYWD, 1 << WT_KEYWORD)               \
36         T(META, 1 << WT_META)                   \
37         T(ALT, 1 << WT_ALT)
38
39 /* String types */
40
41 enum string_type {
42   ST_RESERVED,                          /* Reserved string type */
43   ST_URL,                               /* URL of the document */
44   ST_HOST,                              /* Host name */
45   ST_DOMAIN,                            /* Domain name */
46   ST_REF,                               /* URL reference */
47   ST_BACKREF,                           /* Back-reference (frame or redirect source) */
48 };
49
50 #define STRING_TYPE_NAMES                       \
51         T(URL, 1 << ST_URL)                     \
52         T(HOST, 1 << ST_HOST)                   \
53         T(DOMAIN, 1 << ST_DOMAIN)               \
54         T(REF, 1 << ST_REF)                     \
55         T(BACKREF, 1 << ST_BACKREF)
56
57 #define STRING_TYPES_URL ((1 << ST_URL) | (1 << ST_REF) | (1 << ST_BACKREF))
58 /* These must be indexed in lowercase form */
59 #define STRING_TYPES_CASE_INSENSITIVE ((1 << ST_HOST) | (1 << ST_DOMAIN))
60
61 /* Index card attributes */
62
63 struct card_attr {
64   u32 card;                             /* Reference to card description (either oid or filepos) */
65   u32 site_id;
66   byte weight;
67   byte flags;
68   byte rfu[2];
69 };
70
71 enum card_flag {
72   CARD_FLAG_EMPTY = 1,                  /* Empty document (redirect, robot file etc.) [scanner] */
73   CARD_FLAG_ACCENTED = 2,               /* Document contains accented characters [scanner] */
74   CARD_FLAG_DUP = 4,                    /* Removed as a duplicate [merger] */
75   CARD_FLAG_MERGED = 8,                 /* Destination of a merge [merger] */
76 };
77
78 #define CARD_POS_SHIFT 5                /* Card positions are shifted this # of bytes to the right */
79
80 /* String fingerprints */
81
82 struct fingerprint {
83   byte hash[12];
84 };
85
86 void fingerprint(byte *string, struct fingerprint *fp);
87
88 static inline u32
89 fp_hash(struct fingerprint *fp)
90 {
91   return (fp->hash[0] << 24) | (fp->hash[1] << 16) | (fp->hash[2] << 8) | fp->hash[3];
92 }
93
94 /* Reading of tagged text (Unicode values, tags mapped to 0x80000000 and higher) */
95
96 #define GET_TAGGED_CHAR(p,u) do {                               \
97   u = *p;                                                       \
98   if (u >= 0xc0)                                                \
99     GET_UTF8(p,u);                                              \
100   else if (u >= 0x80)                                           \
101     {                                                           \
102       p++;                                                      \
103       if (u >= 0xb0)                                            \
104         u += 0x80020000;                                        \
105       else if (u >= 0xa0)                                       \
106         u = 0x80010000 + ((u & 0x0f) << 6) + (*p++ & 0x3f);     \
107       else                                                      \
108         u += 0x80000000;                                        \
109     }                                                           \
110   else                                                          \
111     p++;                                                        \
112 } while (0)