From 410e78b472b5195f799a75507e5e3c4ec7e03650 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Sun, 16 Oct 2022 00:55:22 +0530 Subject: xapian: Support combining queries with OR, AND and FILTER operators. * xapian/xapian.scm: Import (srfi srfi-1). (query-combine): New function. (query-and, query-or, query-filter): New public functions. --- xapian/xapian.scm | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'xapian') diff --git a/xapian/xapian.scm b/xapian/xapian.scm index 650c401..f22cfee 100644 --- a/xapian/xapian.scm +++ b/xapian/xapian.scm @@ -22,6 +22,7 @@ #:use-module (rnrs arithmetic bitwise) #:use-module (rnrs bytevectors) #:use-module (ice-9 match) + #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) #:use-module (htmlprag) #:use-module (xapian wrap) @@ -49,6 +50,9 @@ index-text! increase-termpos! parse-query + query-and + query-or + query-filter enquire enquire-mset mset-item-docid @@ -196,6 +200,34 @@ on the database object." (MSetIterator-next head) (loop head result)))))) +(define (query-combine combine-operator default . queries) + (reduce (cut new-Query combine-operator <> <>) + default + queries)) + +(define (query-and . queries) + "Return a query matching only documents matching all @var{queries}. + +In a weighted context, the weight is the sum of the weights for all +queries." + (apply query-combine (Query-OP-AND) (Query-MatchAll) queries)) + +(define (query-or . queries) + "Return a query matching documents which at least one of @var{queries} +match. + +In a weighted context, the weight is the sum of the weights for +matching queries." + (apply query-combine (Query-OP-OR) (Query-MatchNothing) queries)) + +(define (query-filter . queries) + "Return a query matching only documents matching all @var{queries}, +but only take weight from the first of @var{queries}. + +In a non-weighted context, @code{query-filter} and @code{query-and} +are equivalent." + (apply query-combine (Query-OP-FILTER) (Query-MatchAll) queries)) + (define (get-flag flag-thunk value) (if value (flag-thunk) 0)) -- cgit v1.2.3