Index: /trunk/gsdl/src/mgpp/text/GSDLQueryLex.cpp
===================================================================
--- /trunk/gsdl/src/mgpp/text/GSDLQueryLex.cpp	(revision 6120)
+++ /trunk/gsdl/src/mgpp/text/GSDLQueryLex.cpp	(revision 6121)
@@ -224,5 +224,5 @@
 
   // assume it is a term of some sort
-  if (!ParseTerm (here, end, el.text)) {
+  if (!ParseTerm (here, end, el.text))  {
     // parse term returns false if it hasn't parsed anything that is a term
     // here should be the same as it was before 
@@ -253,4 +253,10 @@
     return true;
   }
+  UCArray WITHIN; SetCStr (WITHIN, "WITHIN");
+  if (PrefixLen(el.text, WITHIN)==6) {
+    el.lexType = WithinOpE;
+    return true;
+  }
+  
   el.lexType = TermE;
   return true;
Index: /trunk/gsdl/src/mgpp/text/GSDLQueryLex.h
===================================================================
--- /trunk/gsdl/src/mgpp/text/GSDLQueryLex.h	(revision 6120)
+++ /trunk/gsdl/src/mgpp/text/GSDLQueryLex.h	(revision 6121)
@@ -28,7 +28,7 @@
 // note: white space is ignored
 enum LexType {NoTypeE, OpenBracketE, CloseBracketE, TermE, AndOpE, OrOpE,
-	      NotOpE, NearOpE, QuoteE, IntegerE, TermWeightE, StemMethodE,
-	      RangeE, AtE, TagE, OpenSquareBracketE, CloseSquareBracketE, 
-	      UnknownE};
+	      NotOpE, NearOpE, WithinOpE, QuoteE, IntegerE, TermWeightE, 
+	      StemMethodE, RangeE, AtE, TagE, OpenSquareBracketE, 
+	      CloseSquareBracketE, UnknownE};
 
 struct LexEl {
Index: /trunk/gsdl/src/mgpp/text/GSDLQueryParser.cpp
===================================================================
--- /trunk/gsdl/src/mgpp/text/GSDLQueryParser.cpp	(revision 6120)
+++ /trunk/gsdl/src/mgpp/text/GSDLQueryParser.cpp	(revision 6121)
@@ -92,13 +92,31 @@
 // default is within 20 words
 static void SetRangeValues (TermNode &termNode,
-			    UCArray &nearby) {
+			    UCArray &nearby,
+			    bool reverse) {
   UCArray NEARBY; SetCStr(NEARBY, "NEAR");
+  UCArray WITHIN; SetCStr(WITHIN, "WITHIN");
+  
   if (nearby == NEARBY) { // no modifier
     termNode.startRange = (NEAR_DEFAULT+1)*-1;
     termNode.endRange = NEAR_DEFAULT;
 
+  } else if (nearby == WITHIN) { // no modifier
+    if (reverse) {
+      termNode.startRange = (NEAR_DEFAULT+1)*-1;
+      termNode.endRange = -1;
+    } else {
+      termNode.startRange = NEAR_DEFAULT;
+      termNode.endRange = 0;
+    }
   }
   else { // extract number
-    UCArray::const_iterator here = nearby.begin()+4;
+    UCArray::const_iterator here;
+    bool within = false;
+    if (PrefixLen(nearby, WITHIN)==6) {
+      within=true;
+      here = nearby.begin()+6;
+    } else {
+      here = nearby.begin()+4;
+    }
     UCArray::const_iterator end = nearby.end();
     int size=0;
@@ -107,6 +125,16 @@
       here++;
     }
-    termNode.startRange = -1 * (size+1);
-    termNode.endRange = size;
+    if (within) {
+      if (reverse) {
+	termNode.startRange = size;
+	termNode.endRange = 0;
+      } else {
+	termNode.startRange = -1 * (size+1);
+	termNode.endRange = -1;
+      }
+    } else {
+      termNode.startRange = -1 * (size+1);
+      termNode.endRange = size;
+    }
   }
 }
@@ -241,5 +269,5 @@
         }
       } else if (near) {
-	SetRangeValues(termNode, near_string);
+	SetRangeValues(termNode, near_string, false);
 	near = false;
       }
@@ -257,7 +285,7 @@
 	phrase=true; // start of phrase
       }
-    } else if (el.lexType == NearOpE) {
+    } else if (el.lexType == NearOpE || el.lexType == WithinOpE) {
       if (phrase) {
-	// cant have NEAR op in a phrase - just assume its an actual word
+	// cant have proximity  op in a phrase - just assume its an actual word
 	TermNode termNode;
 	termNode.term = el.text;
@@ -265,5 +293,5 @@
 	proxNode->terms.push_back(termNode);
       } else {
-	// its a NEAR op
+	// its a NEAR or within op
 	near = true;
 	near_string = el.text;
@@ -342,5 +370,5 @@
     ParseTermModifiers (here, end, termNode, defaultStemMethod);
     oldHere = here;  // dont backtrack past here
-    if (ParseLexEl(here, end, el) && el.lexType == NearOpE) {
+    if (ParseLexEl(here, end, el) && (el.lexType == NearOpE || el.lexType == WithinOpE )) {
 	delete proxNode;
 	oldHere = here;
@@ -350,5 +378,5 @@
       LexEl temp_el;
       if (ParseLexEl(here, end, temp_el) && temp_el.lexType == OpenBracketE) {
-	cerr << "GSDLQueryParser: NEAR cannot be followed by a '('\n";
+	cerr << "GSDLQueryParser: NEAR/WITHIN cannot be followed by a '('\n";
 	return NULL;
       }
@@ -357,5 +385,5 @@
       proxNode = (ProxMatchQueryNode *)ParseTerm(here, end, defaultBoolCombine,
 						 defaultStemMethod);
-      SetRangeValues(termNode, el.text);
+      SetRangeValues(termNode, el.text, true);
       proxNode->terms.push_back (termNode);
       return proxNode;
