Index: query.cc
===================================================================
--- query.cc	(revision 7527)
+++ query.cc	(working copy)
@@ -693,6 +693,7 @@
 static Xapian::docid q0;
 static Xapian::doccount hit_no;
 static int percent;
+static Xapian::weight weight;
 static Xapian::doccount collapsed;
 
 static string print_caption(const string &fmt, const vector<string> &param);
@@ -789,6 +790,7 @@
 CMD_url,
 CMD_value,
 CMD_version,
+CMD_weight,
 CMD_MACRO // special tag for macro evaluation
 };
 
@@ -911,6 +913,7 @@
 T(url,		   1, 1, N, 0), // url encode argument
 T(value,	   1, 2, N, 0), // return document value
 T(version,	   0, 0, N, 0), // omega version string
+T(weight,	   0, 0, N, 0), // weight of the current hit
 { NULL,{0,	   0, 0, 0, 0}}
 };
 
@@ -1863,6 +1866,9 @@
 	    case CMD_version:
 		value = "Xapian - "PACKAGE" "VERSION;
 		break;
+	    case CMD_weight:
+		value = double_to_string(weight);
+		break;
 	    default: {
 		args.insert(args.begin(), param[0]);
 		int macro_no = func->second->tag - CMD_MACRO;
@@ -1946,6 +1952,7 @@
 {
     q0 = *(mset[hit_no]);
 
+    weight = mset[hit_no].get_weight();
     percent = mset.convert_to_percent(mset[hit_no]);
     collapsed = mset[hit_no].get_collapse_count();
 
Index: utils.cc
===================================================================
--- utils.cc	(revision 7516)
+++ utils.cc	(working copy)
@@ -1,4 +1,4 @@
-/* utils.cc: string utils for omega
+/* utils.cc: string conversion utility functions for omega
  *
  * Copyright 1999,2000,2001 BrightStation PLC
  * Copyright 2003,2004,2006 Olly Betts
@@ -21,8 +21,11 @@
 
 #include <config.h>
 
+#include "utils.h"
+
+#include <stdio.h> // for sprintf/snprintf
+
 #include <string>
-#include <stdio.h>
 
 using namespace std;
 
@@ -63,6 +66,12 @@
 }
 
 string
+double_to_string(double val)
+{
+    CONVERT_TO_STRING("%f")
+}
+
+string
 date_to_string(int y, int m, int d)
 {
     char buf[11];
Index: utils.h
===================================================================
--- utils.h	(revision 7516)
+++ utils.h	(working copy)
@@ -1,12 +1,11 @@
-/* utils.h: string utils for omega
+/* utils.h: string conversion utility functions for omega
  *
- * Copyright 1999,2000,2001 BrightStation PLC
- * Copyright 2003,2004,2006 Olly Betts
+ * Copyright (C) 2006 Olly Betts
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -15,15 +14,27 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
- * USA
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#ifndef OMEGA_INCLUDED_UTILS_H
+#define OMEGA_INCLUDED_UTILS_H
+
 #include <string>
 
-using std::string;
+/** Converts year, month, day into an 8 character string like: "20061031". */
+std::string date_to_string(int year, int month, int day);
 
-int string_to_int(const string &s);
-string int_to_string(int i);
-string long_to_string(long val);
-string date_to_string(int y, int m, int d);
+/** Converts a double to a string. */
+std::string double_to_string(double value);
+
+/** Converts an int to a string. */
+std::string int_to_string(int value);
+
+/** Converts a long to a string. */
+std::string long_to_string(long value);
+
+/** Converts a string to an int. */
+int string_to_int(const std::string & s);
+
+#endif
Index: docs/omegascript.txt
===================================================================
--- docs/omegascript.txt	(revision 7516)
+++ docs/omegascript.txt	(working copy)
@@ -446,6 +446,10 @@
 $version
 	omega version string - e.g. "Xapian - omega 0.9.2"
 
+$weight
+	raw document weight of the current hit, as a floating point value
+	(mostly useful for debugging purposes).
+
 Numeric Operators:
 ==================
 
