[Xapian-discuss] Matching exact phrases only

James Aylett james-xapian at tartarus.org
Tue Aug 8 16:29:49 BST 2006


On Tue, Aug 08, 2006 at 02:14:48PM +0000, Chris Good wrote:

> > searching on the term 'Centre' (I haven't done any stemming), I get
> > back two matches at 100%, but with relevance 0.095310179804324935. I
> > suspect you'll see something similar.
> 
> That sounds like it might do the job and allow us to filter out such
> matches.  I can't see a way to grab out the docs relevance within omega
> though, at least it's not in the documentation that I have here.

Yes, you're right - that isn't exposed. Try the following patch
(untested, but it builds at least :-):

Index: utils.h
===================================================================
--- utils.h	(revision 7021)
+++ utils.h	(working copy)
@@ -25,4 +25,5 @@
 
 int string_to_int(const string &s);
 string int_to_string(int i);
+string double_to_string(double d);
 string date_to_string(int y, int m, int d);
Index: utils.cc
===================================================================
--- utils.cc	(revision 7021)
+++ utils.cc	(working copy)
@@ -56,6 +56,11 @@
     CONVERT_TO_STRING("%d")
 }
 
+string double_to_string(double val)
+{
+    CONVERT_TO_STRING("%f")
+}
+
 string
 date_to_string(int y, int m, int d)
 {
Index: query.cc
===================================================================
--- query.cc	(revision 7021)
+++ query.cc	(working copy)
@@ -683,6 +683,7 @@
 static Xapian::docid q0;
 static Xapian::doccount hit_no;
 static int percent;
+static double weight;
 static Xapian::doccount collapsed;
 
 static string print_caption(const string &fmt, const vector<string> &param);
@@ -777,6 +778,7 @@
 CMD_url,
 CMD_value,
 CMD_version,
+CMD_weight,
 CMD_MACRO // special tag for macro evaluation
 };
 
@@ -897,6 +899,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 current hit
 { NULL,{0,	   0, 0, 0, 0}}
 };
 
@@ -1852,6 +1855,10 @@
 	    case CMD_version:
 		value = "Xapian - "PACKAGE" "VERSION;
 		break;
+	    case CMD_weight:
+		// relevance
+		value = double_to_string(weight);
+		break;
 	    default: {
 		args.insert(args.begin(), param[0]);
 		int n = i->second->tag - CMD_MACRO;
@@ -1969,6 +1978,7 @@
     q0 = *(mset[hit_no]);
 
     percent = mset.convert_to_percent(mset[hit_no]);
+    weight = mset[hit_no].get_weight();
     collapsed = mset[hit_no].get_collapse_count();
 
     Xapian::Document doc = db.get_document(q0);


James

-- 
/--------------------------------------------------------------------------\
  James Aylett                                                  xapian.org
  james at tartarus.org                               uncertaintydivision.org



More information about the Xapian-discuss mailing list