82 |
82 |
83 util->flush(); |
83 util->flush(); |
84 cpix_Analyzer_destroy(analyzer); |
84 cpix_Analyzer_destroy(analyzer); |
85 } |
85 } |
86 |
86 |
87 void testQuery(Itk::TestMgr * testMgr, const wchar_t *qryStr, int hitLen) |
87 void setupPrefixOptimiseQuery(Itk::TestMgr * testMgr) |
|
88 { |
|
89 cpix_Result |
|
90 result; |
|
91 |
|
92 cpix_IdxDb_dbgScrapAll(&result); |
|
93 ITK_ASSERT(testMgr, |
|
94 cpix_Succeeded(&result), |
|
95 "Could not get rid of all test qbac-idx pairs"); |
|
96 std::auto_ptr<FileIdxUtil> util( new FileIdxUtil ); |
|
97 util->init(true); |
|
98 cpix_Analyzer* analyzer = cpix_Analyzer_create(&result, L"standard"); |
|
99 if ( cpix_Failed( &result) ) ITK_PANIC("Analyzer could not be created"); |
|
100 |
|
101 util->indexFile( CORPUS_PATH "\\query\\query7.txt", analyzer, testMgr ); |
|
102 |
|
103 util->flush(); |
|
104 util->indexFile( CORPUS_PATH "\\query\\query8.txt", analyzer, testMgr ); |
|
105 |
|
106 util->flush(); |
|
107 util->indexFile( CORPUS_PATH "\\query\\query9.txt", analyzer, testMgr ); |
|
108 |
|
109 util->flush(); |
|
110 cpix_Analyzer_destroy(analyzer); |
|
111 |
|
112 } |
|
113 |
|
114 void testQuery(Itk::TestMgr * testMgr, const wchar_t *qryStr, int hitLen, Efield_type ftype = LCPIX_DEFAULT) |
88 { |
115 { |
89 cpix_Result |
116 cpix_Result |
90 result; |
117 result; |
91 int32_t hitsLength = 0; |
118 int32_t hitsLength = 0; |
92 |
119 |
94 |
121 |
95 util->init(false); |
122 util->init(false); |
96 cpix_Analyzer* analyzer = cpix_Analyzer_create(&result, L"standard"); |
123 cpix_Analyzer* analyzer = cpix_Analyzer_create(&result, L"standard"); |
97 if ( cpix_Failed( &result) ) ITK_PANIC("Analyzer could not be created"); |
124 if ( cpix_Failed( &result) ) ITK_PANIC("Analyzer could not be created"); |
98 cpix_QueryParser |
125 cpix_QueryParser |
99 * queryParser = cpix_QueryParser_create(&result, |
126 * queryParser = NULL; |
100 LCPIX_DEFAULT_FIELD, |
127 switch(ftype) |
101 analyzer ); |
128 { |
|
129 case LCPIX_DEFAULT_PREFIX: |
|
130 queryParser = cpix_QueryParser_create(&result,LCPIX_DEFAULT_PREFIX_FIELD,analyzer ); |
|
131 break; |
|
132 case LCPIX_DEFAULT: |
|
133 queryParser = cpix_QueryParser_create(&result,LCPIX_DEFAULT_FIELD,analyzer ); |
|
134 break; |
|
135 } |
102 if (queryParser == NULL) |
136 if (queryParser == NULL) |
103 { |
137 { |
104 cpix_Analyzer_destroy( analyzer ); |
138 cpix_Analyzer_destroy( analyzer ); |
105 ITK_PANIC("Could not create query parser"); |
139 ITK_PANIC("Could not create query parser"); |
106 } |
140 } |
146 |
180 |
147 |
181 |
148 |
182 |
149 void CreatePlainQueryTest(Itk::TestMgr * testMgr) |
183 void CreatePlainQueryTest(Itk::TestMgr * testMgr) |
150 { |
184 { |
151 bool val = true; |
|
152 setupPlainQuery(testMgr); |
185 setupPlainQuery(testMgr); |
153 testQuery(testMgr,L"Nokia", 2); |
186 testQuery(testMgr,L"Nokia", 2); |
154 testQuery(testMgr,L"iNdia", 1); |
187 testQuery(testMgr,L"iNdia", 1); |
155 testQuery(testMgr,L"\"London Finland\"", 1); |
188 testQuery(testMgr,L"\"London Finland\"", 1); |
156 testQuery(testMgr,L"Contents:Nokia", 2); |
189 testQuery(testMgr,L"Contents:Nokia", 2); |
185 // create_xml(val,__func__,__FILE__,__LINE__); |
218 // create_xml(val,__func__,__FILE__,__LINE__); |
186 } |
219 } |
187 |
220 |
188 void CreatePrefixQueryTest(Itk::TestMgr * testMgr) |
221 void CreatePrefixQueryTest(Itk::TestMgr * testMgr) |
189 { |
222 { |
190 bool val = true; |
|
191 setupPrefixQuery(testMgr); |
223 setupPrefixQuery(testMgr); |
192 testQuery(testMgr,L"$prefix(\"new-notes\")", 1); |
224 testQuery(testMgr,L"$prefix(\"new-notes\")", 1); |
193 testQuery(testMgr,L"$prefix(\"notes\")", 1); |
225 testQuery(testMgr,L"$prefix(\"notes\")", 1); |
194 testQuery(testMgr,L"$prefix(\"new\")", 1); |
226 testQuery(testMgr,L"$prefix(\"new\")", 1); |
195 testQuery(testMgr,L"$prefix(\"-india\")", 1); |
227 testQuery(testMgr,L"$prefix(\"-india\")", 1); |
230 testQuery(testMgr,L"$prefix(\">greaterthan\")", 1); |
262 testQuery(testMgr,L"$prefix(\">greaterthan\")", 1); |
231 testQuery(testMgr,L"$prefix(\"worked for motorola .\")", 1); |
263 testQuery(testMgr,L"$prefix(\"worked for motorola .\")", 1); |
232 |
264 |
233 } |
265 } |
234 |
266 |
|
267 void CreatePrefixOptimiseQueryTest(Itk::TestMgr * testMgr) |
|
268 { |
|
269 setupPrefixOptimiseQuery(testMgr); |
|
270 testQuery(testMgr,L"i*", 3,LCPIX_DEFAULT_PREFIX ); |
|
271 testQuery(testMgr,L"in*", 2,LCPIX_DEFAULT_PREFIX ); |
|
272 testQuery(testMgr,L"i?", 3,LCPIX_DEFAULT_PREFIX ); |
|
273 testQuery(testMgr,L"id*", 2,LCPIX_DEFAULT_PREFIX ); |
|
274 testQuery(testMgr,L"c*", 2,LCPIX_DEFAULT_PREFIX ); |
|
275 testQuery(testMgr,L"c?", 2,LCPIX_DEFAULT_PREFIX ); |
|
276 testQuery(testMgr,L"cu*", 2,LCPIX_DEFAULT_PREFIX ); |
|
277 testQuery(testMgr,L"co*", 2,LCPIX_DEFAULT_PREFIX ); |
|
278 testQuery(testMgr,L"d*", 3,LCPIX_DEFAULT_PREFIX ); |
|
279 testQuery(testMgr,L"d?", 3,LCPIX_DEFAULT_PREFIX ); |
|
280 testQuery(testMgr,L"de*", 2,LCPIX_DEFAULT_PREFIX ); |
|
281 testQuery(testMgr,L"do*", 1,LCPIX_DEFAULT_PREFIX ); |
|
282 testQuery(testMgr,L"l*", 3,LCPIX_DEFAULT_PREFIX ); |
|
283 testQuery(testMgr,L"lo*", 2,LCPIX_DEFAULT_PREFIX ); |
|
284 testQuery(testMgr,L"li*", 1,LCPIX_DEFAULT_PREFIX ); |
|
285 testQuery(testMgr,L"wo*", 1,LCPIX_DEFAULT_PREFIX ); |
|
286 testQuery(testMgr,L"pr*", 1,LCPIX_DEFAULT_PREFIX ); |
|
287 testQuery(testMgr,L"r*", 3,LCPIX_DEFAULT_PREFIX ); |
|
288 testQuery(testMgr,L"ru*", 2,LCPIX_DEFAULT_PREFIX ); |
|
289 testQuery(testMgr,L"ra*", 2,LCPIX_DEFAULT_PREFIX ); |
|
290 testQuery(testMgr,L"ri*", 2,LCPIX_DEFAULT_PREFIX ); |
|
291 } |
235 Itk::TesterBase * CreateQueryTests() |
292 Itk::TesterBase * CreateQueryTests() |
236 { |
293 { |
237 using namespace Itk; |
294 using namespace Itk; |
238 |
295 |
239 ContextTester |
296 ContextTester |
240 * qryTests = new ContextTester("Query Tests", NULL); |
297 * qryTests = new ContextTester("Query Tests", NULL); |
241 |
298 |
242 qryTests->add("PlainQueryTest", &CreatePlainQueryTest); |
299 qryTests->add("PlainQueryTest", &CreatePlainQueryTest); |
243 qryTests->add("PrefixQueryTest", &CreatePrefixQueryTest); |
300 qryTests->add("PrefixQueryTest", &CreatePrefixQueryTest); |
|
301 qryTests->add("PrefixOptimiseQueryTest", &CreatePrefixOptimiseQueryTest); |
244 |
302 |
245 return qryTests; |
303 return qryTests; |
246 } |
304 } |
247 |
305 |
248 |
306 |