Changeset 4210 for trunk/indexers
- Timestamp:
- 2003-05-01T10:59:14+12:00 (21 years ago)
- Location:
- trunk/indexers/mgpp/text
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/indexers/mgpp/text/GSDLQueryParser.cpp
r3782 r4210 26 26 static QueryNode *ParseExpression (UCArray::const_iterator &here, 27 27 UCArray::const_iterator end, 28 int defaultBoolC Ombine,28 int defaultBoolCombine, 29 29 int defaultStemMethod); 30 30 … … 216 216 217 217 // expects starting brackets to have been parsed 218 // sets error to true if something has gone wrong 218 219 static void ParseSquareBrackets(UCArray::const_iterator &here, 219 220 UCArray::const_iterator end, 220 221 ProxMatchQueryNode *proxNode, 221 int defaultStemMethod) { 222 int defaultStemMethod, 223 bool & error) { 222 224 223 225 LexEl el; … … 241 243 break; 242 244 } 243 else if (el.lexType == AndOpE) {244 // ignore, the words are AND'ed anyway245 cerr << "and inside []\n";246 }247 else if (el.lexType == OrOpE) {248 cerr << "or inside []\n";249 }250 245 else if (el.lexType == QuoteE) { 251 246 // phrase inside square brackets … … 254 249 } 255 250 else { 256 //error 257 // just ignore for now 258 cerr <<"bad syntax inside []\n"; 251 //error - we set the proxNode to NULL, 252 cerr <<"GSDLQueryParser: bad syntax inside []\n"; 253 error = true; 254 return; 259 255 } 260 256 } // while … … 268 264 UCArray::const_iterator end, 269 265 ProxMatchQueryNode &proxNode, 270 int defaultStemMethod) { 266 int defaultStemMethod, 267 bool &error) { 271 268 LexEl el; 272 269 bool first = true; … … 290 287 291 288 } else { 292 // error 293 break; 289 // error 290 error = true; 291 return; 294 292 } 295 293 } … … 317 315 oldHere = here; // dont backtrack past here 318 316 if (ParseLexEl(here, end, el) && el.lexType == NearOpE) { 319 delete proxNode; 317 delete proxNode; 318 oldHere = here; 319 // this is calling ParseTerm again, but only a subset of the things accepted by ParseTerm are appropriate here. add in some hacks to avoid segmentation faults - kjdon, 04/2003 320 321 // if the next element is a '(' have a syntax error, return NULL 322 LexEl temp_el; 323 if (ParseLexEl(here, end, temp_el) && temp_el.lexType == OpenBracketE) { 324 cerr << "GSDLQueryParser: NEAR cannot be followed by a '('\n"; 325 return NULL; 326 } 327 here = oldHere; // else backtrack 328 320 329 proxNode = (ProxMatchQueryNode *)ParseTerm(here, end, defaultBoolCombine, 321 330 defaultStemMethod); … … 323 332 proxNode->terms.push_back (termNode); 324 333 return proxNode; 325 }326 else {334 335 } else { 327 336 here = oldHere; // backtrack 328 337 proxNode->terms.push_back (termNode); … … 331 340 } 332 341 } else if (el.lexType == QuoteE) { 333 ParsePhrase (here, end, *proxNode, defaultStemMethod); 342 bool error = false; 343 ParsePhrase (here, end, *proxNode, defaultStemMethod, error); 344 if (error) { 345 delete proxNode; 346 return NULL; 347 } 334 348 return proxNode; 335 349 } 336 350 else if (el.lexType == OpenSquareBracketE) { 337 ParseSquareBrackets (here, end, proxNode, defaultStemMethod); 351 bool error = false; 352 ParseSquareBrackets (here, end, proxNode, defaultStemMethod, error); 353 if (error) { 354 delete proxNode; 355 return NULL; 356 } 338 357 ParseProxModifiers (here, end, proxNode); 339 358 return proxNode; … … 353 372 LexEl el; 354 373 QueryNode *curTree = NULL; 355 356 374 UCArray::const_iterator oldHere = here; 357 375 while (ParseLexEl (here, end, el)) { 358 if (el.lexType == OpenSquareBracketE || 359 el.lexType == OpenBracketE || 360 el.lexType == TermE || 361 el.lexType == QuoteE || 362 el.lexType == IntegerE ) { 363 // el.lexType == TagE) { //tag at end of term now 364 // some type of term, back track and parse it 365 here = oldHere; 366 // if default==1, AND, else if==0, OR 367 if (defaultBoolCombine) { 368 curTree = AndAdd (curTree, ParseTerm (here, end, defaultBoolCombine, 369 defaultStemMethod)); 370 } 371 else { 372 curTree = OrAdd (curTree, ParseTerm (here, end, defaultBoolCombine, 373 defaultStemMethod)); 374 } 375 376 } else if (el.lexType == AndOpE) { 377 curTree = AndAdd (curTree, ParseTerm (here, end, defaultBoolCombine, 378 defaultStemMethod)); 379 380 } else if (el.lexType == OrOpE) { 381 curTree = OrAdd (curTree, ParseTerm (here, end, defaultBoolCombine, 382 defaultStemMethod)); 383 384 } else if (el.lexType == NotOpE) { 385 curTree = NotAdd (curTree, ParseTerm (here, end, defaultBoolCombine, 386 defaultStemMethod)); 387 388 } else if (el.lexType == CloseBracketE) { 376 if (el.lexType == CloseBracketE) { 389 377 // parsebracketexpression is waiting for the last bracket, so put it back 390 378 here = oldHere; 391 379 break; 392 393 } else break; 394 380 381 } else if (el.lexType == OpenSquareBracketE || 382 el.lexType == OpenBracketE || 383 el.lexType == TermE || 384 el.lexType == QuoteE || 385 el.lexType == IntegerE ) { 386 387 // some type of term, back track and parse it 388 here = oldHere; 389 390 // parse the term 391 QueryNode * newTerm = ParseTerm (here, end, defaultBoolCombine, 392 defaultStemMethod); 393 if (newTerm == NULL) { 394 delete curTree; 395 return NULL; 396 } 397 398 // if default==1, AND, else if==0, OR 399 if (defaultBoolCombine) { 400 curTree = AndAdd (curTree, newTerm); 401 } 402 else { 403 curTree = OrAdd (curTree, newTerm); 404 } 405 406 } else if (el.lexType == AndOpE) { 407 QueryNode * newTerm = ParseTerm (here, end, defaultBoolCombine, 408 defaultStemMethod); 409 if (newTerm == NULL) { 410 delete curTree; 411 return NULL; 412 } 413 curTree = AndAdd (curTree, newTerm); 414 415 } else if (el.lexType == OrOpE) { 416 QueryNode * newTerm = ParseTerm (here, end, defaultBoolCombine, 417 defaultStemMethod); 418 if (newTerm == NULL) { 419 delete curTree; 420 return NULL; 421 } 422 curTree = OrAdd (curTree, newTerm); 423 424 } else if (el.lexType == NotOpE) { 425 QueryNode * newTerm = ParseTerm (here, end, defaultBoolCombine, 426 defaultStemMethod); 427 if (newTerm == NULL) { 428 delete curTree; 429 return NULL; 430 } 431 curTree = NotAdd (curTree, newTerm); 432 433 } else { 434 435 // syntax error, return NUll 436 delete curTree; 437 return NULL; 438 } 439 395 440 oldHere = here; 396 441 } -
trunk/indexers/mgpp/text/Queryer.cpp
r3365 r4210 242 242 // regular query 243 243 queryTree = ParseQuery (queryArray, defaultBoolCombine, defaultStemMethod); 244 245 // print the query 246 PrintNode (cout, queryTree); 247 248 MGQuery (indexData, queryInfo, queryTree, queryResult, level); 249 if (shortOutput) { 250 queryResult.printShort(cout); 251 cout << "\n"; 252 }else { 253 cout << queryResult; 254 cout << "\n"; 255 } 256 // delete the query 257 if (queryTree != NULL) delete queryTree; 258 queryTree = NULL; 244 if (queryTree == NULL) { 245 cout << "invalid syntax\n"; 246 } else { 247 // print the query 248 PrintNode (cout, queryTree); 249 250 MGQuery (indexData, queryInfo, queryTree, queryResult, level); 251 if (shortOutput) { 252 queryResult.printShort(cout); 253 cout << "\n"; 254 } else { 255 cout << queryResult; 256 cout << "\n"; 257 } 258 // delete the query 259 delete queryTree; 260 queryTree = NULL; 261 } 259 262 } 260 263 }
Note:
See TracChangeset
for help on using the changeset viewer.