Index: /trunk/indexers/mgpp/text/GSDLQueryParser.cpp
===================================================================
--- /trunk/indexers/mgpp/text/GSDLQueryParser.cpp	(revision 4209)
+++ /trunk/indexers/mgpp/text/GSDLQueryParser.cpp	(revision 4210)
@@ -26,5 +26,5 @@
 static QueryNode *ParseExpression (UCArray::const_iterator &here,
 				   UCArray::const_iterator end, 
-				   int defaultBoolCOmbine,
+				   int defaultBoolCombine,
 				   int defaultStemMethod);
 
@@ -216,8 +216,10 @@
 
 // expects starting brackets to have been parsed
+// sets error to true if something has gone wrong
 static void ParseSquareBrackets(UCArray::const_iterator &here,
 				UCArray::const_iterator end,
 				ProxMatchQueryNode *proxNode,
-				int defaultStemMethod) {
+				int defaultStemMethod,
+				bool & error) {
 
   LexEl el;
@@ -241,11 +243,4 @@
       break;
     }
-    else if (el.lexType == AndOpE) {
-      // ignore, the words are AND'ed anyway
-      cerr << "and inside []\n";
-    }
-    else if (el.lexType == OrOpE) {
-      cerr << "or inside []\n";
-    }
     else if (el.lexType == QuoteE) {
       // phrase inside square brackets
@@ -254,7 +249,8 @@
     }
     else {
-      //error
-      // just ignore for now
-      cerr <<"bad syntax inside []\n";
+      //error - we set the proxNode to NULL,
+      cerr <<"GSDLQueryParser: bad syntax inside []\n";
+      error = true;
+      return;
     }
   } // while
@@ -268,5 +264,6 @@
 			 UCArray::const_iterator end,
 			 ProxMatchQueryNode &proxNode, 
-			 int defaultStemMethod) {
+			 int defaultStemMethod,
+			 bool &error) {
   LexEl el;
   bool first = true;
@@ -290,6 +287,7 @@
       
     } else {
-      // error
-      break;
+      // error 
+      error = true;
+      return;
     }
   }
@@ -317,5 +315,16 @@
     oldHere = here;  // dont backtrack past here
     if (ParseLexEl(here, end, el) && el.lexType == NearOpE) {
-      delete proxNode;
+	delete proxNode;
+	oldHere = here;
+      // 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
+      
+      // if the next element is a '(' have a syntax error, return NULL 
+      LexEl temp_el;
+      if (ParseLexEl(here, end, temp_el) && temp_el.lexType == OpenBracketE) {
+	cerr << "GSDLQueryParser: NEAR cannot be followed by a '('\n";
+	return NULL;
+      }
+      here = oldHere; // else backtrack
+	
       proxNode = (ProxMatchQueryNode *)ParseTerm(here, end, defaultBoolCombine,
 						 defaultStemMethod);
@@ -323,6 +332,6 @@
       proxNode->terms.push_back (termNode);
       return proxNode;
-    }
-    else {
+      
+    } else {
       here = oldHere; // backtrack
       proxNode->terms.push_back (termNode);
@@ -331,9 +340,19 @@
     }
   } else if (el.lexType == QuoteE) {
-    ParsePhrase (here, end, *proxNode, defaultStemMethod);
+    bool error = false;
+    ParsePhrase (here, end, *proxNode, defaultStemMethod, error);
+    if (error) {
+      delete proxNode;
+      return NULL;
+    }
     return proxNode;
   }
   else if (el.lexType == OpenSquareBracketE) {
-    ParseSquareBrackets (here, end, proxNode, defaultStemMethod);
+    bool error = false;
+    ParseSquareBrackets (here, end, proxNode, defaultStemMethod, error);
+    if (error) {
+      delete proxNode;
+      return NULL;
+    }
     ParseProxModifiers (here, end, proxNode);
     return proxNode;
@@ -353,44 +372,70 @@
   LexEl el;
   QueryNode *curTree = NULL;
-
   UCArray::const_iterator oldHere = here;
   while (ParseLexEl (here, end, el)) {
-    if (el.lexType == OpenSquareBracketE ||
-	el.lexType == OpenBracketE ||
-	el.lexType == TermE ||
-	el.lexType == QuoteE ||
-	el.lexType == IntegerE ) {
-	//	el.lexType == TagE) { //tag at end of term now
-      // some type of term, back track and parse it
-      here = oldHere;
-      // if default==1, AND, else if==0, OR
-      if (defaultBoolCombine) {
-	curTree = AndAdd (curTree, ParseTerm (here, end, defaultBoolCombine, 
-					      defaultStemMethod));
-      }
-      else {
-	curTree = OrAdd (curTree, ParseTerm (here, end, defaultBoolCombine,
-					     defaultStemMethod));
-      }
-
-    } else if (el.lexType == AndOpE) {
-      curTree = AndAdd (curTree, ParseTerm (here, end, defaultBoolCombine,
-					    defaultStemMethod));
-      
-    } else if (el.lexType == OrOpE) {
-      curTree = OrAdd (curTree, ParseTerm (here, end, defaultBoolCombine,
-					   defaultStemMethod));
-      
-    } else if (el.lexType == NotOpE) {
-      curTree = NotAdd (curTree, ParseTerm (here, end, defaultBoolCombine,
-					    defaultStemMethod));
-      
-    } else if (el.lexType == CloseBracketE) {
+    if (el.lexType == CloseBracketE) {
       // parsebracketexpression is waiting for the last bracket, so put it back
       here = oldHere;
       break;
-    
-    } else break;
-    
+      
+    } else if (el.lexType == OpenSquareBracketE ||
+	       el.lexType == OpenBracketE ||
+	       el.lexType == TermE ||
+	       el.lexType == QuoteE ||
+	       el.lexType == IntegerE ) { 
+      
+      // some type of term, back track and parse it
+      here = oldHere;
+
+      //  parse the term
+      QueryNode * newTerm = ParseTerm (here, end, defaultBoolCombine, 
+				       defaultStemMethod);
+      if (newTerm == NULL) {
+	delete curTree;
+	return NULL;
+      }
+
+      // if default==1, AND, else if==0, OR
+      if (defaultBoolCombine) {
+	curTree = AndAdd (curTree, newTerm);
+      }
+      else {
+	curTree = OrAdd (curTree, newTerm); 
+      }
+      
+    } else if (el.lexType == AndOpE) {
+      QueryNode * newTerm = ParseTerm (here, end, defaultBoolCombine,
+				       defaultStemMethod);
+      if (newTerm == NULL) {
+	delete curTree;
+	return NULL;
+      }
+      curTree = AndAdd (curTree, newTerm);
+      
+    } else if (el.lexType == OrOpE) {
+      QueryNode * newTerm = ParseTerm (here, end, defaultBoolCombine,
+				       defaultStemMethod);
+      if (newTerm == NULL) {
+	delete curTree;
+	return NULL;
+      }
+      curTree = OrAdd (curTree, newTerm);
+      
+    } else if (el.lexType == NotOpE) {
+      QueryNode * newTerm = ParseTerm (here, end, defaultBoolCombine,
+				       defaultStemMethod);
+      if (newTerm == NULL) {
+	delete curTree;
+	return NULL;
+      }
+      curTree = NotAdd (curTree, newTerm); 
+      
+    } else {
+
+      // syntax error, return NUll
+      delete curTree;
+      return NULL;
+    }
+
     oldHere = here;
   }
Index: /trunk/indexers/mgpp/text/Queryer.cpp
===================================================================
--- /trunk/indexers/mgpp/text/Queryer.cpp	(revision 4209)
+++ /trunk/indexers/mgpp/text/Queryer.cpp	(revision 4210)
@@ -242,19 +242,22 @@
       // regular query
       queryTree = ParseQuery (queryArray, defaultBoolCombine, defaultStemMethod);
-
-      // print the query
-      PrintNode (cout, queryTree);
-
-      MGQuery (indexData, queryInfo, queryTree, queryResult, level);
-      if (shortOutput) {
-	queryResult.printShort(cout);
-	cout << "\n";
-      }else {
-	cout << queryResult;
-	cout << "\n";
-      }
-      // delete the query
-      if (queryTree != NULL) delete queryTree;
-      queryTree = NULL;
+      if (queryTree == NULL) {
+	cout << "invalid syntax\n";
+      } else {
+	// print the query
+	PrintNode (cout, queryTree);
+	
+	MGQuery (indexData, queryInfo, queryTree, queryResult, level);
+	if (shortOutput) {
+	  queryResult.printShort(cout);
+	  cout << "\n";
+	} else {
+	  cout << queryResult;
+	  cout << "\n";
+	}
+	// delete the query
+	delete queryTree;
+	queryTree = NULL;
+      }
     }
   }
Index: /trunk/mgpp/text/GSDLQueryParser.cpp
===================================================================
--- /trunk/mgpp/text/GSDLQueryParser.cpp	(revision 4209)
+++ /trunk/mgpp/text/GSDLQueryParser.cpp	(revision 4210)
@@ -26,5 +26,5 @@
 static QueryNode *ParseExpression (UCArray::const_iterator &here,
 				   UCArray::const_iterator end, 
-				   int defaultBoolCOmbine,
+				   int defaultBoolCombine,
 				   int defaultStemMethod);
 
@@ -216,8 +216,10 @@
 
 // expects starting brackets to have been parsed
+// sets error to true if something has gone wrong
 static void ParseSquareBrackets(UCArray::const_iterator &here,
 				UCArray::const_iterator end,
 				ProxMatchQueryNode *proxNode,
-				int defaultStemMethod) {
+				int defaultStemMethod,
+				bool & error) {
 
   LexEl el;
@@ -241,11 +243,4 @@
       break;
     }
-    else if (el.lexType == AndOpE) {
-      // ignore, the words are AND'ed anyway
-      cerr << "and inside []\n";
-    }
-    else if (el.lexType == OrOpE) {
-      cerr << "or inside []\n";
-    }
     else if (el.lexType == QuoteE) {
       // phrase inside square brackets
@@ -254,7 +249,8 @@
     }
     else {
-      //error
-      // just ignore for now
-      cerr <<"bad syntax inside []\n";
+      //error - we set the proxNode to NULL,
+      cerr <<"GSDLQueryParser: bad syntax inside []\n";
+      error = true;
+      return;
     }
   } // while
@@ -268,5 +264,6 @@
 			 UCArray::const_iterator end,
 			 ProxMatchQueryNode &proxNode, 
-			 int defaultStemMethod) {
+			 int defaultStemMethod,
+			 bool &error) {
   LexEl el;
   bool first = true;
@@ -290,6 +287,7 @@
       
     } else {
-      // error
-      break;
+      // error 
+      error = true;
+      return;
     }
   }
@@ -317,5 +315,16 @@
     oldHere = here;  // dont backtrack past here
     if (ParseLexEl(here, end, el) && el.lexType == NearOpE) {
-      delete proxNode;
+	delete proxNode;
+	oldHere = here;
+      // 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
+      
+      // if the next element is a '(' have a syntax error, return NULL 
+      LexEl temp_el;
+      if (ParseLexEl(here, end, temp_el) && temp_el.lexType == OpenBracketE) {
+	cerr << "GSDLQueryParser: NEAR cannot be followed by a '('\n";
+	return NULL;
+      }
+      here = oldHere; // else backtrack
+	
       proxNode = (ProxMatchQueryNode *)ParseTerm(here, end, defaultBoolCombine,
 						 defaultStemMethod);
@@ -323,6 +332,6 @@
       proxNode->terms.push_back (termNode);
       return proxNode;
-    }
-    else {
+      
+    } else {
       here = oldHere; // backtrack
       proxNode->terms.push_back (termNode);
@@ -331,9 +340,19 @@
     }
   } else if (el.lexType == QuoteE) {
-    ParsePhrase (here, end, *proxNode, defaultStemMethod);
+    bool error = false;
+    ParsePhrase (here, end, *proxNode, defaultStemMethod, error);
+    if (error) {
+      delete proxNode;
+      return NULL;
+    }
     return proxNode;
   }
   else if (el.lexType == OpenSquareBracketE) {
-    ParseSquareBrackets (here, end, proxNode, defaultStemMethod);
+    bool error = false;
+    ParseSquareBrackets (here, end, proxNode, defaultStemMethod, error);
+    if (error) {
+      delete proxNode;
+      return NULL;
+    }
     ParseProxModifiers (here, end, proxNode);
     return proxNode;
@@ -353,44 +372,70 @@
   LexEl el;
   QueryNode *curTree = NULL;
-
   UCArray::const_iterator oldHere = here;
   while (ParseLexEl (here, end, el)) {
-    if (el.lexType == OpenSquareBracketE ||
-	el.lexType == OpenBracketE ||
-	el.lexType == TermE ||
-	el.lexType == QuoteE ||
-	el.lexType == IntegerE ) {
-	//	el.lexType == TagE) { //tag at end of term now
-      // some type of term, back track and parse it
-      here = oldHere;
-      // if default==1, AND, else if==0, OR
-      if (defaultBoolCombine) {
-	curTree = AndAdd (curTree, ParseTerm (here, end, defaultBoolCombine, 
-					      defaultStemMethod));
-      }
-      else {
-	curTree = OrAdd (curTree, ParseTerm (here, end, defaultBoolCombine,
-					     defaultStemMethod));
-      }
-
-    } else if (el.lexType == AndOpE) {
-      curTree = AndAdd (curTree, ParseTerm (here, end, defaultBoolCombine,
-					    defaultStemMethod));
-      
-    } else if (el.lexType == OrOpE) {
-      curTree = OrAdd (curTree, ParseTerm (here, end, defaultBoolCombine,
-					   defaultStemMethod));
-      
-    } else if (el.lexType == NotOpE) {
-      curTree = NotAdd (curTree, ParseTerm (here, end, defaultBoolCombine,
-					    defaultStemMethod));
-      
-    } else if (el.lexType == CloseBracketE) {
+    if (el.lexType == CloseBracketE) {
       // parsebracketexpression is waiting for the last bracket, so put it back
       here = oldHere;
       break;
-    
-    } else break;
-    
+      
+    } else if (el.lexType == OpenSquareBracketE ||
+	       el.lexType == OpenBracketE ||
+	       el.lexType == TermE ||
+	       el.lexType == QuoteE ||
+	       el.lexType == IntegerE ) { 
+      
+      // some type of term, back track and parse it
+      here = oldHere;
+
+      //  parse the term
+      QueryNode * newTerm = ParseTerm (here, end, defaultBoolCombine, 
+				       defaultStemMethod);
+      if (newTerm == NULL) {
+	delete curTree;
+	return NULL;
+      }
+
+      // if default==1, AND, else if==0, OR
+      if (defaultBoolCombine) {
+	curTree = AndAdd (curTree, newTerm);
+      }
+      else {
+	curTree = OrAdd (curTree, newTerm); 
+      }
+      
+    } else if (el.lexType == AndOpE) {
+      QueryNode * newTerm = ParseTerm (here, end, defaultBoolCombine,
+				       defaultStemMethod);
+      if (newTerm == NULL) {
+	delete curTree;
+	return NULL;
+      }
+      curTree = AndAdd (curTree, newTerm);
+      
+    } else if (el.lexType == OrOpE) {
+      QueryNode * newTerm = ParseTerm (here, end, defaultBoolCombine,
+				       defaultStemMethod);
+      if (newTerm == NULL) {
+	delete curTree;
+	return NULL;
+      }
+      curTree = OrAdd (curTree, newTerm);
+      
+    } else if (el.lexType == NotOpE) {
+      QueryNode * newTerm = ParseTerm (here, end, defaultBoolCombine,
+				       defaultStemMethod);
+      if (newTerm == NULL) {
+	delete curTree;
+	return NULL;
+      }
+      curTree = NotAdd (curTree, newTerm); 
+      
+    } else {
+
+      // syntax error, return NUll
+      delete curTree;
+      return NULL;
+    }
+
     oldHere = here;
   }
Index: /trunk/mgpp/text/Queryer.cpp
===================================================================
--- /trunk/mgpp/text/Queryer.cpp	(revision 4209)
+++ /trunk/mgpp/text/Queryer.cpp	(revision 4210)
@@ -242,19 +242,22 @@
       // regular query
       queryTree = ParseQuery (queryArray, defaultBoolCombine, defaultStemMethod);
-
-      // print the query
-      PrintNode (cout, queryTree);
-
-      MGQuery (indexData, queryInfo, queryTree, queryResult, level);
-      if (shortOutput) {
-	queryResult.printShort(cout);
-	cout << "\n";
-      }else {
-	cout << queryResult;
-	cout << "\n";
-      }
-      // delete the query
-      if (queryTree != NULL) delete queryTree;
-      queryTree = NULL;
+      if (queryTree == NULL) {
+	cout << "invalid syntax\n";
+      } else {
+	// print the query
+	PrintNode (cout, queryTree);
+	
+	MGQuery (indexData, queryInfo, queryTree, queryResult, level);
+	if (shortOutput) {
+	  queryResult.printShort(cout);
+	  cout << "\n";
+	} else {
+	  cout << queryResult;
+	  cout << "\n";
+	}
+	// delete the query
+	delete queryTree;
+	queryTree = NULL;
+      }
     }
   }
