Merge icu_chain into zebramaps.
[idzebra-moved-to-github.git] / include / index_types.h
1 /* $Id: index_types.h,v 1.2 2007-10-25 19:25:00 adam Exp $
2    Copyright (C) 1995-2007
3    Index Data ApS
4
5 This file is part of the Zebra server.
6
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
21 */
22
23 /** 
24     \file
25     \brief Definitions for Zebra's index types
26 */
27
28 #ifndef ZEBRA_INDEX_TYPES_H
29 #define ZEBRA_INDEX_TYPES_H
30
31 #include <yaz/yconfig.h>
32 #include <yaz/xmltypes.h>
33
34 YAZ_BEGIN_CDECL
35
36 /** \brief zebra index types handle (ptr) */
37 typedef struct zebra_index_types_s *zebra_index_types_t;
38
39 /** \brief zebra index type handle (ptr) */
40 typedef struct zebra_index_type_s *zebra_index_type_t;
41
42 /** \brief creates index types handler/object from file
43     \param fname filename
44     \returns handle (NULL if unsuccessful)
45
46     Config file format:
47     \verbatim
48     <indextypes>
49       <indextype id="*:w" position="1" alwaysmatches="1" firstinfield="1"
50         locale="en">
51         <!-- conversion rules for words -->
52       </indextype>
53       <indextype id="*:p" position="0" alwaysmatches="0" firstinfield="0"
54         locale="en">
55         <!-- conversion rules for phrase -->
56       </indextype>
57       <indextype id="*:s" sort="1" 
58         locale="en">
59         <!-- conversion rules for phrase -->
60       </indextype>
61     </indextypes>
62    \endverbatim
63  */
64 zebra_index_types_t zebra_index_types_create(const char *fname);
65
66 /** \brief destroys index rules object
67     \param types handle
68  */
69 void zebra_index_types_destroy(zebra_index_types_t types);
70
71
72 /** \brief creates index types handler/object from xml Doc
73     \param doc Libxml2 document
74     \returns handle (NULL if unsuccessful)
75
76     Similar to zebra_index_types_create
77 */
78 zebra_index_types_t zebra_index_types_create_doc(xmlDocPtr doc);
79
80
81 /** \brief lookup of index type
82     \param types types
83     \param id id to search for
84     \returns pattern ID
85 */
86 const char *zebra_index_type_lookup_str(zebra_index_types_t types, 
87                                         const char *id);
88
89
90 /** \brief get index type of a given ID
91     \param types types
92     \param id ID to search for
93     \returns index type handle
94 */
95 zebra_index_type_t zebra_index_type_get(zebra_index_types_t types, 
96                                         const char *id);
97
98 /** \brief check whether index type is of type 'index'
99     \param type index type
100     \retval 1 YES
101     \retval 0 NO
102 */
103 int zebra_index_type_is_index(zebra_index_type_t type);
104
105 /** \brief check whether index type is of type 'sort'
106     \param type index type
107     \retval 1 YES
108     \retval 0 NO
109 */
110 int zebra_index_type_is_sort(zebra_index_type_t type);
111
112 /** \brief check whether index type is of type 'staticrank'
113     \param type index type
114     \retval 1 YES
115     \retval 0 NO
116 */
117 int zebra_index_type_is_staticrank(zebra_index_type_t type);
118
119
120 /** \brief tokenize a term for an index type
121     \param type index type
122     \param buf term buffer (pass 0 to continue with previous buf)
123     \param len term length
124     \param result_buf resulting token buffer
125     \param result_len resulting token length
126     \retval 1 token read and result is in result_buf
127     \retval 0 no token read (no more tokens in buf)
128 */
129 int zebra_index_type_tokenize(zebra_index_type_t type,
130                               const char *buf, size_t len,
131                               const char **result_buf, size_t *result_len);
132
133 YAZ_END_CDECL
134
135 #endif
136 /*
137  * Local variables:
138  * c-basic-offset: 4
139  * indent-tabs-mode: nil
140  * End:
141  * vim: shiftwidth=4 tabstop=8 expandtab
142  */
143