]> mj.ucw.cz Git - libucw.git/blob - lib/index.h
912925102cff78a1f7f731d06be1dbdcc7ff2742
[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   WT_URL,                               /* Word extracted from document URL */
25   WT_MAX
26 };
27
28 /* Descriptive names used for user output */
29 #define WORD_TYPE_USER_NAMES                                                    \
30    "reserved", "text", "emph", "small", "title", "hdr1", "hdr2", "keywd",       \
31    "meta", "alt", "urlword", "type11", "type12", "type13", "type14", "type15"
32
33 /* Keywords for word type names */
34 #define WORD_TYPE_NAMES                         \
35         T(WORD, ~0)                             \
36         T(TEXT, 1 << WT_TEXT)                   \
37         T(EMPH, 1 << WT_EMPH)                   \
38         T(SMALL, 1 << WT_SMALL)                 \
39         T(TITLE, 1 << WT_TITLE)                 \
40         T(HDR, (1 << WT_SMALL_HEADING) | (1 << WT_BIG_HEADING))  \
41         T(HDR1, 1 << WT_SMALL_HEADING)          \
42         T(HDR2, 1 << WT_BIG_HEADING)            \
43         T(KEYWD, 1 << WT_KEYWORD)               \
44         T(META, 1 << WT_META)                   \
45         T(ALT, 1 << WT_ALT)                     \
46         T(URLWORD, 1 << WT_URL)
47
48 /* These types are not shown in document contexts */
49 #define WORD_TYPES_HIDDEN (1 << WT_URL)
50
51 /* String types */
52
53 enum string_type {
54   ST_RESERVED,                          /* Reserved string type */
55   ST_URL,                               /* URL of the document */
56   ST_HOST,                              /* Host name */
57   ST_DOMAIN,                            /* Domain name */
58   ST_REF,                               /* URL reference */
59   ST_BACKREF,                           /* Back-reference (frame or redirect source) */
60   ST_MAX
61 };
62
63 #define STRING_TYPE_USER_NAMES                                                  \
64    "URL", "host", "domain", "ref", "backref", "type5", "type6", "type7",        \
65    "type8", "type9", "type10", "type11", "type12", "type13", "type14", "type15"
66
67 #define STRING_TYPE_NAMES                       \
68         T(URL, 1 << ST_URL)                     \
69         T(HOST, 1 << ST_HOST)                   \
70         T(DOMAIN, 1 << ST_DOMAIN)               \
71         T(REF, 1 << ST_REF)                     \
72         T(BACKREF, 1 << ST_BACKREF)
73
74 #define STRING_TYPES_URL ((1 << ST_URL) | (1 << ST_REF) | (1 << ST_BACKREF))
75 /* These must be indexed in lowercase form */
76 #define STRING_TYPES_CASE_INSENSITIVE ((1 << ST_HOST) | (1 << ST_DOMAIN))
77
78 /* Index card attributes */
79
80 struct card_attr {
81   u32 card;                             /* Reference to card description (either oid or filepos) */
82   u32 site_id;
83   byte weight;
84   byte flags;
85   byte rfu[2];
86 };
87
88 enum card_flag {
89   CARD_FLAG_EMPTY = 1,                  /* Empty document (redirect, robot file etc.) [scanner] */
90   CARD_FLAG_ACCENTED = 2,               /* Document contains accented characters [scanner] */
91   CARD_FLAG_DUP = 4,                    /* Removed as a duplicate [merger] */
92   CARD_FLAG_MERGED = 8,                 /* Destination of a merge [merger] */
93 };
94
95 #define CARD_POS_SHIFT 5                /* Card positions are shifted this # of bytes to the right */
96
97 /* String fingerprints */
98
99 struct fingerprint {
100   byte hash[12];
101 };
102
103 void fingerprint(byte *string, struct fingerprint *fp);
104
105 static inline u32
106 fp_hash(struct fingerprint *fp)
107 {
108   return (fp->hash[0] << 24) | (fp->hash[1] << 16) | (fp->hash[2] << 8) | fp->hash[3];
109 }
110
111 /* Reading of tagged text (Unicode values, tags mapped to 0x80000000 and higher) */
112
113 #define GET_TAGGED_CHAR(p,u) do {                               \
114   u = *p;                                                       \
115   if (u >= 0xc0)                                                \
116     GET_UTF8(p,u);                                              \
117   else if (u >= 0x80)                                           \
118     {                                                           \
119       p++;                                                      \
120       if (u >= 0xb0)                                            \
121         {                                                       \
122           if (u != 0xb0)                                        \
123             ASSERT(0);                                          \
124           u += 0x80020000;                                      \
125         }                                                       \
126       else if (u >= 0xa0)                                       \
127         {                                                       \
128           ASSERT(*p >= 0x80 && *p <= 0xbf);                     \
129           u = 0x80010000 + ((u & 0x0f) << 6) + (*p++ & 0x3f);   \
130         }                                                       \
131       else                                                      \
132         u += 0x80000000;                                        \
133     }                                                           \
134   else                                                          \
135     p++;                                                        \
136 } while (0)