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