Xpace
indexlist.h
Go to the documentation of this file.
1 
2 /**************************************************************
3  **
4  ** @file index/indexlist.h
5  **
6  ** Copyright (C) 2012 Xpace, LLC. All rights reserved
7  **
8  ** www.xpace.net
9  **
10  **************************************************************/
11 
12 #if !defined XPACE_INDEXLIST_H
13 #define XPACE_INDEXLIST_H
14 
15 #include <vector>
16 #include <map>
17 
18 #include "base/config.h"
19 #include "index/index.h"
20 
21 namespace Xpace
22 {
23  class indexListImpl;
24 
26  {
27  public :
28  /// An empty index list
29  IndexList
30  ();
31 
32  /// open an already-existing index list,
33  /// or create one with this Configuration
34  /// @param config the Configuration
35  /// @param overwrite if true, delete if list already exists
36  /// @throw CantOpen
37  explicit IndexList
38  (const Configuration& config,
39  bool overwrite = false);
40 
41  /// open an already-existing index list
42  /// @param iiFile the index-index file
43  /// @param idFile the actual indexes
44  /// &throw CantOpen
45  IndexList
46  (const String& iiFile,
47  const String& idFile);
48 
49  /// create a new reference to a list
50  /// @param rhs the list
51  IndexList
52  (const IndexList& rhs);
53  /// make this refer to a list
54  /// @param rhs the list
55  IndexList& operator=
56  (const IndexList& rhs);
57 
58  ~IndexList
59  ();
60 
61  /// @return the number of indexes in the list
62  uint getCount
63  ()
64  const;
65 
66  /// Get the Configuration of an index
67  /// @param indexNum the index number
68  /// @return the index's Configuration
69  const Configuration& getIndexConfig
70  (uint indexNum)
71  const;
72 
73  /// Find indexes that include a field
74  /// @param tag the field's tag
75  /// @param pos which of the indexes containing the field to return
76  /// @return number of the pos'th index that contains the field, ~0 for none
77  size_t getIndexByField
78  (const String& tag,
79  size_t pos = 0)
80  const;
81 
82  /// open an index by name
83  /// @param indexName the index to get
84  /// @retval indexNum fill in the index's number
85  /// @return the found index, Index() if not found
86  Index& openIndex
87  (const String& indexName,
88  uint* indexNum = 0,
89  Configuration config = Configuration());
90  const Index& openIndex
91  (const String& indexName,
92  uint* indexNum = 0,
93  Configuration config = Configuration())
94  const;
95 
96  /// open an index by number
97  /// @param indexNum the number of the index to get
98  /// @param config if != Configuration(), override index's Configuration with this one
99  /// @return the found index, Index() if not found
100  Index& openIndex
101  (uint indexNum,
102  Configuration config = Configuration());
103  const Index& openIndex
104  (uint indexNum,
105  Configuration config = Configuration())
106  const;
107 
108  /// @param index index to add
109  /// @return number of added index
110  uint addIndex
111  (Index& index);
112 
113  #ifdef XPACE_REFLIST_H
114  /// @param query a query string
115  /// @param recCount for NOT searches
116  /// @return a RefListCursor into the result
117  RefListCursor eval
118  (String query,
119  uint64 recCount = 0)
120  const;
121 
122  #ifdef QDOM_H
123  /// @param query a search tree
124  /// @param recCount for NOT searches
125  /// @return a RefListCursor into the result
126  RefListCursor eval
127  (QDomNode query,
128  uint64 recCount = 0)
129  const;
130  #endif
131  #endif
132 
133  #if defined(XPACE_STORE_H) || defined(XPACE_TABLE_H) || defined DOCUMENTATION
134 
135  /// bulk build
136 
137  /// status callback
138  struct BuildStatus
139  {
141  () :
142  maxMemory(~0),
143  memUsed(0)
144  {
145  }
146 
147  virtual ~BuildStatus()
148  {
149  }
150 
151  /// @param how many refs indexed
152  /// @param term how many terms indexed
153  /// @param unique how many unique terms indexed
154  /// @return term interval to continue, 0 to stop
155  virtual uint operator()
156  (uint64 ref,
157  uint64 term,
158  uint64 unique,
159  size_t pageListBytes,
160  size_t totalPageBytes,
161  size_t sortBytes,
162  size_t termPoolBytes)
163  = 0;
164  size_t maxMemory; ///< fillin - use no more than this much memory
165  size_t memUsed; ///< how much memory is actually being used by this build
166  };
167  #endif
168 
169  #if defined(XPACE_TABLE_H)
170  /// @param table build from this Table
171  /// @param bst build status callback
172  /// @param wst write status callback (for temp files)
173  /// @return true if completed, false if stopped by callback
174  bool build
175  (Table* table,
176  BuildStatus* bst = 0,
177  Index::WriteStatus* wst = 0);
178  #endif
179 
180  /// write in current state
181  /// @param wst write status callback
182  /// @return true if successful and complete, false if failed or stopped by callback
183  bool write
184  (Index::WriteStatus* st = 0);
185 
186  /// speed up range search for indexes in a list
187  /// @param config specifies from/to files, indexes to be oprimized
188  /// @return true if successful, false if failed of stopped by callback
189  bool range
190  (const Configuration& config,
191  Index::WriteStatus* st = 0);
192 
193  /// merge a list of index lists
194  /// @param config merge to a new index list with this configuration
195  /// @param list list of lindx lists to merge
196  /// @return true if successful and complete, false if failed or stopped by callback
197  static
198  bool merge
199  (const Configuration& config,
200  const std::vector<IndexList*>& list,
201  Index::WriteStatus* st = 0);
202 
203  class CantOpen : public Exception
204  {
205  public :
206  CantOpen
207  (const Configuration& conf,
208  const Exception& why = Exception()) :
209  Exception("Can't open index list from configuration \"%1\".", why)
210  {
211  addParam(conf.toString());
212  };
213  };
214 
215  class CantOpenIndex : public Exception
216  {
217  public :
219  (const String& name) :
220  Exception("Can't open index \"%1\".")
221  {
222  addParam(name);
223  };
224 
226  (size_t indexNum,
227  const Exception& why = Exception()) :
228  Exception("Can't open index# \"%1\".", why)
229  {
230  addParam(String::setNum(indexNum));
231  }
232  };
233 
235 
236  static const char* TAG;
237  private :
238  static const char* II_TAG;
239  static const char* ID_TAG;
240 
241  friend class indexListImpl;
242  indexListImpl* impl;
243  };
244 
245  #if (defined TESTING || !defined NDEBUG) && !defined DOCUMENTATION
246  //void XPACE_EXPORT testIndexes
247  // (File* configFile,
248  // uint checks);
249  #endif
250 
251 } // namespace
252 
253 #endif
254 
A low-level data holder.
Definition: types_c.h:82
size_t memUsed
how much memory is actually being used by this build
Definition: indexlist.h:165
unsigned int uint
Definition: types.h:75
static DECLARE_CONFIG const char * TAG
Definition: indexlist.h:236
Each high-level Xpace object has a Configuration.
Definition: config.h:29
A string, Unicode UTF-16 and reference-counted.
Definition: types.h:269
unsigned long long uint64
Definition: types.h:87
static String setNum(int64 n)
Make a string from a number.
const Xpace_Char16 * name
Sink callbacks for table data.
Definition: table_c.h:141
base class for a configurable object inherit from this to make your object configurable ...
Definition: config.h:255
String toString() const
write this index; could take a while status callback
Definition: index.h:97
#define DECLARE_CONFIG
Definition: sharedimpl.h:323
A cursor into a list of references - e.g., a search result A single reference is an array of uint64s...
Definition: reflist.h:26
Xpace project main namespace
Definition: datetime.h:18
An index.
Definition: index.h:24
size_t maxMemory
fillin - use no more than this much memory
Definition: indexlist.h:164

current as of Wed Jun 10 2026 12:00:05