Index: /trunk/gsdl/src/mgpp/text/MGQuery.cpp
===================================================================
--- /trunk/gsdl/src/mgpp/text/MGQuery.cpp	(revision 860)
+++ /trunk/gsdl/src/mgpp/text/MGQuery.cpp	(revision 861)
@@ -587,17 +587,20 @@
 
   unsigned long resultsSize = queryInfo.maxDocs;
-  if (resultsSize == 0 || resultsSize > result.ranks.size())
-    resultsSize = result.ranks.size();
+  if (resultsSize == 0 || resultsSize > result.docs.size())
+    resultsSize = result.docs.size();
   
   // sort results by rank if needed
-  LTRank ltRank;
+  GTRank gtRank;
   if (queryInfo.sortByRank) {
+    // need in ascending order for SelectAddHeap
     MakeHeap (result.docs.begin(), result.ranks.begin(),
-	      resultsSize, ltRank);
+	      resultsSize, gtRank);
     SelectAddHeap (result.docs.begin(), result.ranks.begin(), resultsSize,
 		   result.docs.begin()+resultsSize,
 		   result.ranks.begin()+resultsSize,
-		   result.ranks.size()-resultsSize, ltRank);
-    SortHeap (result.docs.begin(), result.ranks.begin(), resultsSize, ltRank);
+		   result.ranks.size()-resultsSize, gtRank);
+
+    // sort into descending order
+    SortHeap (result.docs.begin(), result.ranks.begin(), resultsSize, gtRank);
   }
   
@@ -609,5 +612,5 @@
     
     for (i=0; i<resultsSize; i++) {
-      result.ranks[i] = result.ranks[i] * 
+      result.ranks[i] =  result.ranks[i] *
 	indexData.weightData.GetLowerApproxDocWeight (result.docs[i]) /
 	GetExactDocWeight (indexData.exactWeightsFile, exactDiskPtr,
@@ -618,12 +621,14 @@
     if (queryInfo.sortByRank) {
       MakeHeap (result.docs.begin(), result.ranks.begin(),
-		resultsSize, ltRank);
+		resultsSize, gtRank);
       SortHeap (result.docs.begin(), result.ranks.begin(),
-		resultsSize, ltRank);
+		resultsSize, gtRank);
     }
   }
 
   // get rid of unwanted ranking results
-  if (!result.ranks.empty() && !queryInfo.needRankInfo) {
+  if (result.ranks.empty()) {
+    // do nothing
+  } else if (!queryInfo.needRankInfo) {
     result.ranks.erase(result.ranks.begin(), result.ranks.end());
   } else {
Index: /trunk/gsdl/src/mgpp/text/Makefile.in
===================================================================
--- /trunk/gsdl/src/mgpp/text/Makefile.in	(revision 860)
+++ /trunk/gsdl/src/mgpp/text/Makefile.in	(revision 861)
@@ -273,5 +273,5 @@
 
 
-LIB_OBJS = Queryer$o mg_files$o mg_errors$o locallib$o invf$o UCArray$o \
+LIB_OBJS = mg_files$o mg_errors$o locallib$o invf$o UCArray$o \
            FIvfLevelInfo$o FragLevelConvert$o Terms$o MGQuery$o \
            IndexData$o stemmer$o Weights$o TextGet$o text$o FText$o \
Index: /trunk/gsdl/src/mgpp/text/QueryResultsSort.h
===================================================================
--- /trunk/gsdl/src/mgpp/text/QueryResultsSort.h	(revision 860)
+++ /trunk/gsdl/src/mgpp/text/QueryResultsSort.h	(revision 861)
@@ -104,5 +104,5 @@
   
   unsigned long i = 0;
-  for (i=0; i<size; i++)
+  for (i=1; i<=size; i++)
     PushHeap (docNumHeap, parallelHeap, i, comp);
 }
@@ -132,5 +132,5 @@
   unsigned long i;
   for (i=0; i<addSize; i++) {
-    if (comp(*(parallelHeap), *(parallelAdd+i))) {
+    if (comp(*(parallelAdd+i), *(parallelHeap))) {
       swap (*(docNumHeap), *(docNumAdd+i));
       swap (*(parallelHeap), *(parallelAdd+i));
Index: /trunk/gsdl/src/mgpp/text/Queryer.cpp
===================================================================
--- /trunk/gsdl/src/mgpp/text/Queryer.cpp	(revision 860)
+++ /trunk/gsdl/src/mgpp/text/Queryer.cpp	(revision 861)
@@ -75,5 +75,5 @@
   QueryInfo queryInfo;
   SetCStr (queryInfo.docLevel, "Document");
-  queryInfo.maxDocs = 100000;
+  queryInfo.maxDocs = 10;
   queryInfo.sortByRank = true;
   queryInfo.exactWeights = false;
Index: /trunk/gsdl/src/mgpp/text/Weights.cpp
===================================================================
--- /trunk/gsdl/src/mgpp/text/Weights.cpp	(revision 860)
+++ /trunk/gsdl/src/mgpp/text/Weights.cpp	(revision 861)
@@ -111,5 +111,5 @@
   // decompress the weight
   if (table != NULL) return table[c];
-  else return (L * pow (B, (double) c));
+  return (L * pow (B, (double) c));
 }
 
Index: /trunk/gsdl/src/mgpp/text/mg_weights_build.cpp
===================================================================
--- /trunk/gsdl/src/mgpp/text/mg_weights_build.cpp	(revision 860)
+++ /trunk/gsdl/src/mgpp/text/mg_weights_build.cpp	(revision 861)
@@ -48,4 +48,7 @@
 /*
    $Log$
+   Revision 1.3  2000/01/18 23:24:19  rjmcnab
+   fixed a few more bugs
+
    Revision 1.2  2000/01/18 03:53:24  rjmcnab
    Fixed a couple of bugs and made building silent if needed.
@@ -242,5 +245,5 @@
   while (here != end) {
 //      cout << *here << "\n";
-    WriteF (weightsFile, *here);
+    WriteF (weightsFile, sqrt (*here));
     here++;
   }
